FFmpeg on Clear Linux including H.264 and VP9 acceleration

Initially, mpv couldn’t even play videos. After adding env LD_LIBRARY_PATH=/usr/local/lib now able to play videos

1 Like

What ritual is this? :thinking:

i made it up. the poem is from shakspear’s macbeth

you might also want to add /usr/local/lib64

It also works with VLC and others

Yea, I don’t know why ldconfig doesn’t work, so I add them to .bashrc file

My firefox can’t work properly with gfx.webrender.software set to false. so the ffmpeg still use CPU to decode the video even with enhanced-h246ify. Nothing different with chrome. I rembered that my gpu can do encode x264/h264 on Debian with OBS. :thinking:

how to install rubberband? i got libsndfile issue :slightly_frowning_face:

i installed it from source.
i install a large amount of things from source.
you don’t need librubberband for mpv. you can use scaletempo2 with mpv --af=scaletempo2 or press ` (backtick) when mpv is open and do set af scaletempo2
https://mpv.io/manual/master/#audio-filters-scaletempo2[ (this link doesn’t work properly due to trailing “[”)
https://mpv.io/manual/master/#audio-filters

https://mpv.io/manual/master/#command-interface-set-%3Cname%3E-%3Cvalue%3E

(librubberband and scaletempo is only useful for when changing playback speed.)

you don’t need any of the other options either.
openal is a 3D sound API (for ao option). pipewire or pulseaudio work just fine
libplacebo is used for the optional gpu-next video output (vo). gpu works just fine
libmpv may be used by other applications to utilize mpv.

hmm, rubberband need JNI library, LADSPA plugin, LV2 plugin and vamp plugin
so i got this problem

  • jni.h not found, i have installed java and java13
  • lv2 plugin got error
/usr/bin/ld: /usr/local/lib64/libsndfile.a(rpe.c.o): warning: relocation against `gsm_NRFAC' in read-only section `.text'
/usr/bin/ld: /usr/local/lib64/libsndfile.a(sndfile.c.o): relocation R_X86_64_PC32 against symbol `sf_errno' can not be used when making a shared object; recompile with -fPIC
  • LADSPA plugin got error
/usr/bin/ld: /usr/local/lib/libfftw3f.a(assert.o): warning: relocation against `stdout@@GLIBC_2.2.5' in read-only section `.text'
/usr/bin/ld: /usr/local/lib/libfftw3f.a(hc2hc-direct.o): warning: relocation against `fftwf_mksolver_hc2hc_hook' in read-only section `.text'
/usr/bin/ld: /usr/local/lib/libfftw3f.a(assert.o): relocation R_X86_64_PC32 against symbol `stdout@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC

i don’t compile it with those

Message: Not building Java Native Interface: jni.h header not found
Message: Not building LADSPA plugin: ladspa.h header not found
Message: Not building LV2 plugin: lv2.h header not found
Message: Not building Vamp plugin: Vamp dependency not found

libsndfile is included in bundle transcoding-support

there is a bundle devpkg-fftw. what is it doing in /usr/local?

Installed that, but doesn’t work

Ah I build that from source

it is missing the pkg-config (*.pc) file. these are usually packaged with devpkg-* names e.g devpkg-fftw.
other stuff may use pkg-config files to find packages.

1 Like

I have an Intel Celeron N4000 with UHD 600 Intel graphics on an HP Stream 14" laptop and installed Brave Browser. All video on all platforms works out of the box. Fb,Twitter, Tubi, Instagram, Tic Tok not sure how to clock it to get actual performance numbers but all playback is smooth.

1 Like

Can I see see your intel_gpu_top while playing video playback(h264 codec)?
Thanks

Hardware acceleration requires installing FFmpeg on Clear Linux. Also, ensure you have ~/.config/firefox.conf as mentioned in the documentation. This is what I have for Intel graphics, supporting wayland and x11.

export FONTCONFIG_PATH=/usr/share/defaults/fonts
export LD_LIBRARY_PATH=/usr/local/lib

# Uncomment one to override the default driver. Check first with vainfo.
# export LIBVA_DRIVER_NAME=i965
# export LIBVA_DRIVER_NAME=iHD

if [[ $XDG_SESSION_TYPE == wayland ]]
then
    export EGL_PLATFORM=wayland
    export MOZ_ENABLE_WAYLAND=1
else
    export MOZ_DISABLE_WAYLAND=1
    export MOZ_X11_EGL=1
fi

export MOZ_ACCELERATED=1
export MOZ_USE_XINPUT2=1
export MOZ_WEBRENDER=1

Firefox 103 has been released. I’m running the Firefox bundle included with Clear Linux, not the flatpak version. The following will reset Firefox. Be sure to quit out of Firefox first.

$ rm -fr ~/.firefox ~/.mozilla

Run Firefox and click on the drop down menu and select Help > About Firefox and update if prompted. Restart Firefox afterwards.

Go to about:config and set media.ffmpeg.vaapi.enabled to true. That’s all the changes needed to enable hardware acceleration for Intel Graphics. Restart Firefox.

Install the enhanced-h264ify extension. The default blocks VP8, VP9, and AV1.

[ ] Block 60fps video
[ ] Block h264
[x] Block VP8
[x] Block VP9
[x] Block AV1
[ ] Disable Loudness Normalization

Determine if the iHD VA driver works.

$ LIBVA_DRIVER_NAME=iHD vainfo
libva info: VA-API version 1.15.0
libva info: User environment variable requested driver 'iHD'
libva info: Trying to open /usr/lib64/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_13
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.15 (libva 2.15.0)
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 22.2.0 ()
vainfo: Supported profile and entrypoints
      VAProfileNone                   :	VAEntrypointVideoProc
      VAProfileNone                   :	VAEntrypointStats
      VAProfileMPEG2Simple            :	VAEntrypointVLD
      VAProfileMPEG2Simple            :	VAEntrypointEncSlice
      VAProfileMPEG2Main              :	VAEntrypointVLD
      VAProfileMPEG2Main              :	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointFEI
      VAProfileH264High               :	VAEntrypointVLD
      VAProfileH264High               :	VAEntrypointEncSlice
      VAProfileH264High               :	VAEntrypointFEI
      VAProfileVC1Simple              :	VAEntrypointVLD
      VAProfileVC1Main                :	VAEntrypointVLD
      VAProfileVC1Advanced            :	VAEntrypointVLD
      VAProfileJPEGBaseline           :	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline:	VAEntrypointFEI
      VAProfileVP8Version0_3          :	VAEntrypointVLD

Also check i965.

$ LIBVA_DRIVER_NAME=i965 vainfo
libva info: VA-API version 1.15.0
libva info: User environment variable requested driver 'i965'
libva info: Trying to open /usr/lib64/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_1_15
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.15 (libva 2.15.0)
vainfo: Driver version: Intel i965 driver for Intel(R) Broadwell - 2.4.1
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            :	VAEntrypointVLD
      VAProfileMPEG2Simple            :	VAEntrypointEncSlice
      VAProfileMPEG2Main              :	VAEntrypointVLD
      VAProfileMPEG2Main              :	VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline:	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointEncSlice
      VAProfileH264High               :	VAEntrypointVLD
      VAProfileH264High               :	VAEntrypointEncSlice
      VAProfileH264MultiviewHigh      :	VAEntrypointVLD
      VAProfileH264MultiviewHigh      :	VAEntrypointEncSlice
      VAProfileH264StereoHigh         :	VAEntrypointVLD
      VAProfileH264StereoHigh         :	VAEntrypointEncSlice
      VAProfileVC1Simple              :	VAEntrypointVLD
      VAProfileVC1Main                :	VAEntrypointVLD
      VAProfileVC1Advanced            :	VAEntrypointVLD
      VAProfileNone                   :	VAEntrypointVideoProc
      VAProfileJPEGBaseline           :	VAEntrypointVLD
      VAProfileVP8Version0_3          :	VAEntrypointVLD
      VAProfileVP9Profile0            :	VAEntrypointVLD

Although the vainfo output reports VP9 as supported using the i965 driver, it doesn’t work for me and hangs the entire X11 desktop (i.e. unblocking VP9 in enhanced-h265ify). So for my particular setup, an Intel Core i7-5557U CPU, I need to block VP8, VP9, and AV1.

Both VA drivers i965 and iHD support hardware acceleration playing h264 videos. For example, Big Buck Bunny 60fps.

$ sudo intel_gpu_top

One may specify either i965 or iHD in ~/.config/firefox.conf to override the default. On my system the iHD driver is used unless I set LIBVA_DRIVER_NAME explicitly. Choose newer iHD over i965 if iHD works well for you.

export LIBVA_DRIVER_NAME=i965
export LIBVA_DRIVER_NAME=iHD

I’m also running GNOME on x11.

$ echo $XDG_SESSION_TYPE
x11

Finally, I also tested GNOME on wayland. Hardware acceleration is working using either i965 or the iHD VA driver. Try the i965 driver in ~/.config/firefox.conf if iHD hiccups for you or vice versa.

$ echo $XDG_SESSION_TYPE
wayland
1 Like

@marioroy It seems that the github repo doesn’t exits anymore, did you canceled it?

Yes. Having to install large bundles simply to get a few dev files was the deciding factor.

The FFmpeg binaries can be found at Clear Fraction. The bundle names are codecs or codecs-cuda. The latter includes the VA-API backend drivers for NVIDIA graphics plus FFmpeg built supporting CUDA.

The other bits, for running various browsers, can be found in the HWAccel folder.

In a Nutshell:

  • Using NVIDIA graphics? The nvidia-driver-on-clear-linux repo is completed.
  • Want FFmpeg? Choose codecs or codecs-cuda from Clear Fraction.
  • Want Chromium or derivative? The HWAccel folder provides the bin and desktop files. Quite simply, it involves copying the launch script(s) and associated desktop file(s) to your home directory. This has evolved over time and now includes the complimentary updater script which also serves as the installer.

Video decode acceleration:

  • Firefox is good to go using NVIDIA graphics. FFmpeg is not required.
  • Using AMD or Intel graphics? From testing some time ago, FFmpeg was needed using Firefox. The Firefox configuration file or launch script sets the LD_LIBRARY_PATH accordingly.

Chromium or derivative:

  • Using NVIDIA graphics? Chromium has made changes recently to use DMA-BUF. This is causing the VDPAU backend driver to fail. I updated the launch scripts to use Vulkan. Unfortunately, video playback is choppy. So, I added an Opt-in if block for Wayland to use --ozone-platform=x11. Simply uncomment the if statement for better playback.
  • I’m not sure about other graphics.
3 Likes

Trying to play video with mpv:

(+) Video --vid=1 () (h264 1280x720 30.000fps)
(+) Audio --aid=1 --alang=eng (
) (aac 2ch 48000Hz)
File tags:
Title: 646712245768485
[vo/gpu] VT_GETMODE failed: Inappropriate ioctl for device
[vo/gpu/opengl] Failed to set up VT switcher. Terminal switching will be unavailable.
*** MESA_GLSL_CACHE_DISABLE is deprecated; use MESA_SHADER_CACHE_DISABLE instead ***
[vo/gpu] Failed to commit ModeSetting atomic request (-13)
[vo/gpu/opengl] Failed to set CRTC for connector 95: Permission denied
*** MESA_GLSL_CACHE_DISABLE is deprecated; use MESA_SHADER_CACHE_DISABLE instead ***
[vo/gpu-next] Can’t handle VT release - signal already used
[vo/gpu-next/opengl] Failed to set up VT switcher. Terminal switching will be unavailable.
*** MESA_GLSL_CACHE_DISABLE is deprecated; use MESA_SHADER_CACHE_DISABLE instead ***
[vo/gpu-next] Failed to commit ModeSetting atomic request (-13)
[vo/gpu-next/opengl] Failed to set CRTC for connector 95: Permission denied
*** MESA_GLSL_CACHE_DISABLE is deprecated; use MESA_SHADER_CACHE_DISABLE instead ***
Error opening/initializing the selected video_out (–vo) device.
Video: no video
Failed to initialize a decoder for codec ‘aac’.
Audio: no audio
No video or audio streams selected.

Exiting… (Errors when loading file)

Edit: You put mpv in codecs bundle! And I was needed to remove it from /usr/bin.
For now it is ok!

2 Likes

You may want to remove the Clear Linux mpv bundle so that /usr/bin/mpv is not installed in later OS updates.

sudo swupd bundle-remove mpv
1 Like

Exactly did that, thanks.

@marioroy you wrote you created Readme, but it is 404. So I searched the topic and found --enable-features=VaapiVideoDecoder flag for Chromium. So I tried the followung:

flatpak run com.github.Eloston.UngoogledChromium --enable features=VaapiVideoDecoder

and felt no difference at all.