How to enable hardware accelerated video decoder for browsers?

I just noticed none of the 3 browsers I have installed (F, brave, vivaldi) are actually using hardware decoder for youtube videos, I have a laptop with a ryzen 4500u and when I play any 720p video on youtube, all the cores’ utilization jumps up to ~22% from what I can tell, none of the methods I tried (enabling flags and stuff : [HowTo] Enable Hardware Video Acceleration / Video Decode In Google Chrome, Brave, Vivaldi And Opera Browsers)

then I read a more concerning reply from a user on reddit, https://www.reddit.com/r/debian/comments/17khtrk/no_hardware_acceleration_of_videos_amd_ryzen_7/?rdt=41398
so apparently hardware acceleration has been removed?

is this true? are there any workarounds?

Please search the forum - there is several topics on the matter.

https://forum.manjaro.org/t/unstable-manjaro-community-mesa-nonfree-codecs/135012

hi, i followed the instructions on the nonfree.eu site, these to be more specific…

Install
Remove deprecated signatures
    sudo rm -f /var/lib/pacman/sync/mesa-nonfree.*.sig
Locally trust CI key
    sudo pacman-key --recv-keys B728DB23B92CB01B && \
        sudo pacman-key --lsign-key B728DB23B92CB01B
Switch to Manjaro unstable branch and
    sudo pacman-mirrors -aS unstable && \
        sudo pacman -Syu
Download repo configuration
    sudo sh -c "curl -s https://nonfree.eu/unstable/ > /etc/pacman.d/mesa-nonfree.pre.repo.conf"
Inject repo configuration in pacman.conf
The config must precede the core repo to work

    sudo sed -i '/^\[core\]/i \Include = /etc/pacman.d/mesa-nonfree.pre.repo.conf\n' /etc/pacman.conf

then a Syyu

and rebooted, do I need to do anything else?

youtube still doesn’t seem to be using the hardware decoder…

https://wiki.archlinux.org/title/Firefox#Hardware_video_acceleration

You may also need firefox-vaapi.

The Ryzen 4500u may not support YouTube’s AV1 video format hardware decoding (my Ryzen 7 5800h, which is more recent, doesn’t).

So, to play YouTube videos with the hardware decoder you might want to go to your YouTube account settings Playback and performance section & change the AV1 settings to “Prefer AV1 for SD”.

Videos up to 480p will then use AV1 (software decode) for playback & higher resolutions will use VP9 (which should be hardware decoded as long as you have configured Firefox correctly).

When playing a YouTube video, you can also right-click on the video & select “Stats for nerds” to see which video & audio codecs the video is using:

Screenshot_20240101_114850

to piggy-back on @scotty65’s suggestion…

For those who do not have an account, or need finer control there are addons like enhanced-h264ify, which despite its name actually allows control over a number of formats, ie for me (because I cannot use av01);

image

1 Like

I’m not sure that’s the case, when I switched to windows 11(dualboot) videos on edge seems to use a decoder called D3D11… sorry if I’m being dumb… :sweat_smile:

d3-d11 is Direct3D 11, a part of DirectX.
Linux does not have DirectX.

By default on linux youtube will probably be trying to play AV1 - Wikipedia for hardware acceleration… but only so many (newer) GPUs support it. So there may be reasons to configure which format youtube serves.

We dont really care what windoze does … the question is what is available to you on linux.

This will depend on your hardware.
Show us inxi -Fazy and I might be able to tell you step-by-step.

EDIT
Oh right its a ryzen 4500u. If thats accurate then I am pretty sure you dont have accelerated av1, so the above suggestions to disable it might make sense.
We can double check your available formats with

vainfo

acceleration for vp9 seems to work on firefox, tested at 4k(CPU utilisation ~ 18%), but not on the chromium based browsers…

Make sure to have checked
https://wiki.archlinux.org/title/Chromium#Hardware_video_acceleration

ok, i thought both windows and linux used the same hardware decoders :sweat_smile:

inxi -Fazy op:

Graphics:
  Device-1: AMD Renoir [Radeon RX Vega 6 ] vendor: Hewlett-Packard
    driver: amdgpu v: kernel arch: GCN-5 code: Vega process: GF 14nm
    built: 2017-20 pcie: gen: 3 speed: 8 GT/s lanes: 16 link-max: gen: 4
    speed: 16 GT/s ports: active: eDP-1 empty: DP-1,DP-2,HDMI-A-1
    bus-ID: 04:00.0 chip-ID: 1002:1636 class-ID: 0300 temp: 47.0 C
  Device-2: Cheng Uei Precision Industry (Foxlink) HP Wide Vision HD
    Integrated Webcam driver: uvcvideo type: USB rev: 2.0 speed: 480 Mb/s
    lanes: 1 mode: 2.0 bus-ID: 3-4:3 chip-ID: 05c8:03cb class-ID: 0e02
  Display: x11 server: X.Org v: 21.1.10 with: Xwayland v: 23.2.3
    compositor: kwin_x11 driver: X: loaded: amdgpu unloaded: modesetting
    alternate: fbdev,vesa dri: radeonsi gpu: amdgpu display-ID: :0 screens: 1
  Screen-1: 0 s-res: 1920x1080 s-dpi: 96 s-size: 508x285mm (20.00x11.22")
    s-diag: 582mm (22.93")
  Monitor-1: eDP-1 mapped: eDP model: BOE Display 0x0868 built: 2019
    res: 1920x1080 hz: 60 dpi: 158 gamma: 1.2 size: 309x174mm (12.17x6.85")
    diag: 355mm (14") ratio: 16:9 modes: max: 1920x1080 min: 640x480
  API: EGL v: 1.5 hw: drv: amd radeonsi platforms: device: 0 drv: radeonsi
    surfaceless: drv: radeonsi x11: drv: radeonsi inactive: gbm,wayland
  API: OpenGL v: 4.6 vendor: amd mesa v: 23.3.2-arch10.1 glx-v: 1.4
    direct-render: yes renderer: AMD Radeon Graphics (radeonsi renoir LLVM
    16.0.6 DRM 3.54 6.6.8-2-MANJARO) device-ID: 1002:1636 memory: 500 MiB
    unified: no
  API: Vulkan v: 1.3.274 layers: N/A device: 0 type: integrated-gpu name: AMD
    Radeon Graphics (RADV RENOIR) driver: mesa radv v: 23.3.2-arch10.1
    device-ID: 1002:1636 surfaces: xcb,xlib

vainfo op:

Trying display: wayland
Trying display: x11
vainfo: VA-API version: 1.20 (libva 2.20.1)
vainfo: Driver version: Mesa Gallium driver 23.3.2-arch10.1 for AMD Radeon Graphics (radeonsi, renoir, LLVM 16.0.6, DRM 3.54, 6.6.8-2-MANJARO)
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      VAProfileHEVCMain               : VAEntrypointVLD
      VAProfileHEVCMain               : VAEntrypointEncSlice
      VAProfileHEVCMain10             : VAEntrypointVLD
      VAProfileHEVCMain10             : VAEntrypointEncSlice
      VAProfileJPEGBaseline           : VAEntrypointVLD
      VAProfileVP9Profile0            : VAEntrypointVLD
      VAProfileVP9Profile2            : VAEntrypointVLD
      VAProfileNone                   : VAEntrypointVideoProc

This confirms VP9 as your probably preferred format.
(you can use the older h264 as well).
And probably means you do want to configure the yt format to avoid AV1.
(whether by yt itself or by an extension… and oh yeah heres a chrome version: https://chromewebstore.google.com/detail/enhanced-h264ify/omkfmpieigblcllmkgbflkikinpkodlk)

And if its working for FF … then chrom* is probably just a matter of the correct flags.

1 Like

that’s probably it… do you know what flags to use? The guide seems to have been depreciated… i tried using

--enable-features=VaapiVideoEncoder,VaapiVideoDecodeLinuxGL --enable-gpu

also, in vivaldi://gpu decode is listed as enabled, yet yt doesn’t use it? here’s part of vivaldi://gpu I couldn’t understand much of it

Graphics Feature Status
=======================
*   Canvas: Hardware accelerated
*   Canvas out-of-process rasterization: Disabled
*   Direct Rendering Display Compositor: Disabled
*   Compositing: Hardware accelerated
*   Multiple Raster Threads: Enabled
*   OpenGL: Enabled
*   Rasterization: Hardware accelerated on all pages
*   Raw Draw: Disabled
*   Skia Graphite: Disabled
*   Video Decode: Hardware accelerated
*   Video Encode: Hardware accelerated
*   Vulkan: Disabled
*   WebGL: Hardware accelerated
*   WebGL2: Hardware accelerated
*   WebGPU: Disabled

Driver Bug Workarounds
======================
*   adjust_src_dst_region_for_blitframebuffer
*   clear_pixel_unpack_buffer_before_copyteximage
*   count_all_in_varyings_packing
*   decode_encode_srgb_for_generatemipmap
*   disable_post_sub_buffers_for_onscreen_surfaces
*   disable_software_to_accelerated_canvas_upgrade
*   enable_webgl_timer_query_extensions
*   exit_on_context_lost
*   force_cube_map_positive_x_allocation
*   force_int_or_srgb_cube_texture_complete
*   init_texture_max_anisotropy
*   disabled_extension_GL_KHR_blend_equation_advanced
*   disabled_extension_GL_KHR_blend_equation_advanced_coherent
*   disabled_extension_GL_MESA_framebuffer_flip_y

Problems Detected
=================
*   WebGPU has been disabled via blocklist or the command line.
    Disabled Features: webgpu

*   Mesa drivers in Linux handle varyings without static use incorrectly:
    (http://crbug.com/333885)
    Applied Workarounds: count_all_in_varyings_packing

*   Linux AMD drivers incorrectly return initial value of 1 for TEXTURE_MAX_ANISOTROPY:
    (http://crbug.com/348237)
    Applied Workarounds: init_texture_max_anisotropy

*   Linux ATI drivers crash on binding incomplete cube map texture to FBO:
    (http://crbug.com/518889)
    Applied Workarounds: force_cube_map_positive_x_allocation

*   Disable partial swaps on Mesa drivers (detected with GL_VERSION):
    (http://crbug.com/339493)
    Applied Workarounds: disable_post_sub_buffers_for_onscreen_surfaces

*   adjust src/dst region if blitting pixels outside framebuffer on Linux AMD:
    (http://crbug.com/664740)
    Applied Workarounds: adjust_src_dst_region_for_blitframebuffer

*   Disable KHR_blend_equation_advanced until cc shaders are updated:
    (http://crbug.com/661715)
    Applied Workarounds: disable(GL_KHR_blend_equation_advanced),
        disable(GL_KHR_blend_equation_advanced_coherent)

*   Decode and Encode before generateMipmap for srgb format textures on Linux AMD:
    (http://crbug.com/634519)
    Applied Workarounds: decode_encode_srgb_for_generatemipmap

*   Software to Accelerated canvas update breaks Linux AMD:
    (http://crbug.com/710029)
    Applied Workarounds: disable_software_to_accelerated_canvas_upgrade

*   Force integer or srgb cube map texture complete on Linux AMD:
    (http://crbug.com/712117)
    Applied Workarounds: force_int_or_srgb_cube_texture_complete

*   Expose WebGL's disjoint_timer_query extensions on platforms with site isolation:
    (http://crbug.com/808744), (http://crbug.com/870491)
    Applied Workarounds: enable_webgl_timer_query_extensions

*   AMD Linux driver crashes when copyTexImage2D is called with PIXEL_UNPACK_BUFFER set to an uninitialized buffer:
    (http://crbug.com/859998)
    Applied Workarounds: clear_pixel_unpack_buffer_before_copyteximage

*   Some drivers can't recover after OUT_OF_MEM and context lost:
    (http://crbug.com/893177)
    Applied Workarounds: exit_on_context_lost

*   Disable GL_MESA_framebuffer_flip_y for desktop GL:
    (http://crbug.com/964010)
    Applied Workarounds: disable(GL_MESA_framebuffer_flip_y)

also in the terminal, I get an error(but browser launches nonetheless) not sure if that’s relevant…

[18185:18477:0101/084313.121544:ERROR:vaapi_video_decoder.cc(1226)] failed Initialize()ing the frame pool
[18137:18137:0101/084322.566829:ERROR:CONSOLE(10)] "Uncaught ReferenceError: $ is not defined", source: chrome://flags/app.js (10)
[18137:18137:0101/084322.628461:ERROR:CONSOLE(4)] "Uncaught TypeError: Cannot read properties of undefined (reading 'toString')", source: chrome://gpu/info_view.js (4)
[18137:18137:0101/084322.628668:ERROR:CONSOLE(4)] "Uncaught TypeError: Cannot read properties of undefined (reading 'toString')", source: chrome://gpu/info_view.js (4)
[18137:18137:0101/084322.633360:ERROR:CONSOLE(4)] "Uncaught TypeError: Cannot read properties of undefined (reading 'toString')", source: chrome://gpu/info_view.js (4)
[18137:18137:0101/084322.634175:ERROR:CONSOLE(4)] "Uncaught TypeError: Cannot read properties of undefined (reading 'toString')", source: chrome://gpu/info_view.js (4)
[18137:18137:0101/084322.675082:ERROR:CONSOLE(4)] "Uncaught TypeError: Cannot read properties of undefined (reading 'toString')", source: chrome://gpu/info_view.js (4)

thanks for the help

I had been using
~/.config/chromium-flags

--flag-switches-begin
--start-maximized
--force-dark-mode
--ignore-gpu-blocklist
--high-dpi-support=1
--enable-parallel-downloading
--enable-accelerated-video
--enable-accelerated-mjpeg-decode
--enable-gpu-rasterization
--enable-oop-rasterization
--enable-quic
--enable-zero-copy
--enable-drdc
--canvas-oop-rasterization
--ozone-platform-hint=x11
--use-gl=angle
--enable-smooth-scrolling
--enable-accelerated-video-decode
--enable-native-gpu-memory-buffers
--enable-features=VaapiVideoDecodeLinuxGL,WebUIDarkMode,MarkHttpAs,StrictOriginIsolation,VaapiVideoDecoder,VaapiVideoEncoder,VaapiVideo,CanvasOopRasterization,VaapiIgnoreDriverChecks,PlatformHEVCDecoderSupport
--disable-features=UseChromeOSDirectVideoDecoder,HardwareMediaKeyHandling,OmniboxUIExperimentHideSteadyStateUrlPathQueryAndRef,OmniboxUIExperimentHideSteadyStateUrlScheme,OmniboxUIExperimentHideSteadyStateUrlTrivialSubdomains,ShowManagedUi
--flag-switches-end

But I just checked chrome://media-internals/
and found

…so it looks like things may have changed again.
(though, to be fair, its ungoogled-chromum and I havent been using it recently)
HW-Accel with the big browsers on linux always feels like a moving target.

1 Like

from what i found, that’s so true. :smiling_face_with_tear: