IsmaelMartinez / teams-for-linux

Unofficial Microsoft Teams for Linux client
GNU General Public License v3.0
2.7k stars 223 forks source link

Possible guide to enable HW DEcoding and ENcoding in electron #1324

Open D-MLink opened 1 month ago

D-MLink commented 1 month ago

From using teams4linux daily i notice my laptop goes into turbo mode whenever i enter a call and everyone turns on their cameras (and I have to turn on mine) The teams v2 has a call health feature and displays that the videos are decrypted using SW.

Looking to solve my issue, i tried to force enable HW encoding on chromium. Managed to do it but my video comes out with artifacts... But the performance improved. image

So I found this repo: https://github.com/StaZhu/enable-chromium-hevc-hardware-decoding which may help to enable HW encoding/decoding in electron. I know it talks about hevc and teams uses h264, but there might something that helps enabling both.

For reference, my work laptop is running Pop!_OS 22.04 on a i7-10610U

IsmaelMartinez commented 1 month ago

You should be able to use the ['enable-features', 'PlatformHEVCDecoderSupport'] like in https://github.com/IsmaelMartinez/teams-for-linux/tree/develop/app/config#electron-cli-flags . I haven't test it but that would enable that flag as described in https://github.com/electron/electron/issues/35392 . We use electron 29 (Just upgraded to 30 today) so this should be well supported.

Thanks for the link and the info!

D-MLink commented 1 month ago

Thanks for the config option, but so far I tried several flags, including the ones I use to make it work on chromium, and I still get SW video processing on Teams for linux

D-MLink commented 1 month ago

Here's the config I tried for reference: "electronCLIFlags":[ ["ignore-gpu-blocklist"], ["enable-zero-copy"], ["enable-features", "WebRTCPipeWireCapturer,PlatformHEVCDecoderSupport,CanvasOopRasterization,VaapiIgnoreDriverChecks,VaapiVideoDecoder,VaapiVideoEnco> ["enable-accelerated-video-decode"], ["disable-features","UseChromeOSDirectVideoDecoder"] ]

raul-klg commented 1 month ago

Hi! I'm also pursuing this feature, and I think there has been a mistake pasting the configuration, I think you meant:

    "electronCLIFlags": [
        ["ignore-gpu-blocklist"],
        ["enable-zero-copy"],
        ["enable-features", "WebRTCPipeWireCapturer,PlatformHEVCDecoderSupport,CanvasOopRasterization,VaapiIgnoreDriverChecks,VaapiVideoDecoder,VaapiVideoEncoder"],
        ["enable-accelerated-video-decode"],
        ["disable-features","UseChromeOSDirectVideoDecoder"]
    ]

right?

Also, in order to check if GPU decoding is enabled I'd like to follow these troubleshoot steps but I don't know how to get there in the t4l window. Hints appreciated ;)

D-MLink commented 1 month ago

Hi! I'm also pursuing this feature, and I think there has been a mistake pasting the configuration, I think you meant:

    "electronCLIFlags": [
        ["ignore-gpu-blocklist"],
        ["enable-zero-copy"],
        ["enable-features", "WebRTCPipeWireCapturer,PlatformHEVCDecoderSupport,CanvasOopRasterization,VaapiIgnoreDriverChecks,VaapiVideoDecoder,VaapiVideoEncoder"],
        ["enable-accelerated-video-decode"],
        ["disable-features","UseChromeOSDirectVideoDecoder"]
  ]

right?

Also, in order to check if GPU decoding is enabled I'd like to follow these troubleshoot steps but I don't know how to get there in the t4l window. Hints appreciated ;)

yes! i copied from the nano windows and missed also the VaapiVideoDecodeLinuxGL feature flag I also dont know how to open the chrome:gpu window

IsmaelMartinez commented 1 month ago

I wonder if it is worth opening an issue/question in the electron repository. Maybe some of those flags aren't supported. Or check on running from source (check the contributing.md file). Maybe is the bundling that is blocking some areas... but I would suspect is electron land issue/limitation.

donjan commented 2 weeks ago

I'm also still struggling with this (as reported in https://github.com/IsmaelMartinez/teams-for-linux/issues/1246). Teams pair programming on that particular laptop (ThinkPad X1C 8th Gen) is a punishment.

My current settings are essentially the same as other's above: ~/.config/teams-for-linux/config.json

{
    "electronCLIFlags": [
        ["ignore-gpu-blocklist"],
        ["enable-zero-copy"],
        ["enable-accelerated-video-decode"],
        ["enable-features", "WebRTCPipeWireCapturer,PlatformHEVCDecoderSupport,CanvasOopRasterization,VaapiIgnoreDriverChecks,VaapiVideoDecoder,VaapiVideoEncoder,VaapiVideoDecodeLinuxGL"],
        ["disable-features","UseChromeOSDirectVideoDecoder"]
    ]
}

How can I check if these settings even get consumed?

...

Now... to get a bit off of Ismael's back, I have to admit I'm apparently struggling with basic Chromium acceleration already.

When launching the browser with

chromium-browser --ignore-gpu-blocklist --enable-zero-copy --enable-accelerated-video-decode --enable-features=WebRTCPipeWireCapturer,PlatformHEVCDecoderSupport,CanvasOopRasterization,VaapiIgnoreDriverChecks,VaapiVideoDecoder,VaapiVideoEncoder,VaapiVideoDecodeLinuxGL --disable-features=UseChromeOSDirectVideoDecoder

And checking about:gpu, I get two promising sections:

1 2

Which means I can't hardware-decode AV1, YouTube's default for most videos, but I can force H264 with the h264ify extension (which works correctly, checking "stats for nerds"). Yet despite what the images above might imply, intel_gpu_top shows no bar for the video line when playing a H264 video, and there is massive CPU usage. It does use video in Firefox and mpv, with nicer CPU usage, so my hardware & OS can in fact accelerate the decoding. Chromium 101.0.4951.15 on Ubuntu 22.04.4 can't. I don't want to derail this too much, but can anyone reproduce this underlying issue?

IsmaelMartinez commented 1 week ago

have you check in the electron issues https://github.com/electron/electron/issues ? This might be something other users of electron have experienced. Hopefully something in there helps you. Sorry

mirenradia commented 2 days ago

I think HW processing is now enabled for me with the electronCLIFlags config option suggest above (Intel Alder Lake iGPU). I noticed that it only worked with no effects enabled and reverted back to SW processing when I enabled the blur effect.