Bash Script to Add H.264 Support for Firefox

Last updated on May 2 2020.

I made this script based on this post:

To run it, execute the following in terminal

#!/usr/bin/env bash

## References:

## Install dependencies
echo -e "\e[33m\xe2\x8f\xb3 Install the following dependencies: 'c-basic', 'devpkg-libva', and 'git' ...\e[m"
sudo swupd bundle-add c-basic devpkg-libva git

## Clone the ffmpeg git repository if it doesn't exist; or update it if it exists
echo -e "\e[33m\xe2\x8f\xb3 Get latest FFmpeg source repository ...\e[m"
if [ -d "FFmpeg" ];then
  # shellcheck disable=SC2164
  cd FFmpeg
  git fetch
  git clone
  # shellcheck disable=SC2164
  cd FFmpeg

## Get the latest non-dev release
echo -e "\e[33m\xe2\x8f\xb3 Checkout the latest non-dev release ...\e[m"
git checkout tags/"$(git tag -l | sed -n -E '/^n[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$/p' | sort | tail -1)"

## Build FFmpeg, which would be installed under /opt/ffmpeg
echo -e "\e[33m\xe2\x8f\xb3 Building ...\e[m"
echo -e "\e[32m If the installation is successful, it would be available under \e[33m/opt/ffmpeg\e[32m.\e[m"
read -rp "Press any key to continue ... " -n1 -s
if ! ./configure --prefix=/opt/ffmpeg --enable-shared || ! make || ! sudo make install; then
  echo -e "\e[31m Installation failed! Aborting...\e[m"
  exit 1

## Configure the dynamic linker configuration to include /opt/ffmpeg/lib
echo -e "\e[33m\xe2\x8f\xb3 Configuring dynamic linker configuration ...\e[m"
if [ ! -f /etc/ ] || \
  grep -q 'include /etc/ld\.so\.conf\.d/\*\.conf' /etc/; then
  printf "include /etc/*.conf" | sudo tee -a /etc/
if [ ! -d /etc/ ]; then
  sudo mkdir /etc/
if [ ! -f /etc/ ] && \
  grep -q '/opt/ffmpeg/lib' /etc/; then
  echo "/opt/ffmpeg/lib" | sudo tee /etc/
echo -e "\e[32m Updating dynamic linker run-time bindings and library cache ...\e[m"
sudo ldconfig

## Add ffmpeg to library path of Firefox
echo -e "\e[33m\xe2\x8f\xb3 Add FFmpeg to libarry path of Firefox ...\e[m"
if [ ! -f "${HOME}/.config/firefox.conf" ] || \
  grep -q 'export LD_LIBRARY_PATH' "${HOME}/.config/firefox.conf"; then
  echo "export LD_LIBRARY_PATH=/opt/ffmpeg/lib" >> "${HOME}/.config/firefox.conf"
  grep -q 'export LD_LIBRARY_PATH=.*/opt/ffmpeg/lib.*' "${HOME}/.config/firefox.conf" \
      || sed -i 's#export LD_LIBRARY_PATH=#&/opt/ffmpeg/lib:#' "${HOME}/.config/firefox.conf"

You can download it here.


Nice job. I tried this out thought but it failed at line 60 for me.

./install.bash: line 60; /root/.config/firefox.con: No such file or directory

If I use sudo -E install.bash then the install finished. However, nothing showed up in /opt/ffmpeg that the script told me should be there if everything was successful. I didn’t notice any other errors and I did reboot afterwards. I ran the script again and it completes but nothing is in /opt/ffmpeg but there is a ~/.config/firefox.conf file at least. It seems like it just skips the compile step. Looking at file modification date only some config miles were modified so nothing was compiled.

1 Like

I have the exact same problem.

@eadams @Qushy
I’ve update the script. Please take a look

1 Like

Thanks for updating but I am still having issues. I have to use sudo -E ./install.bash for it to create the file in $HOME/.config/firefox.conf but it never seems to do the compile. I have nothing in /opt/ffmpeg

... previous output
Enabled bsfs:
aac_adtstoasc           dca_core                filter_units            hapqa_extract           mjpeg2jpeg              mpeg2_metadata          prores_metadata         truehd_core             vp9_superframe_split
av1_frame_split         dump_extradata          h264_metadata           hevc_metadata           mjpega_dump_header      mpeg4_unpack_bframes    remove_extradata        vp9_metadata
av1_metadata            eac3_core               h264_mp4toannexb        hevc_mp4toannexb        mov2textsub             noise                   text2movsub             vp9_raw_reorder
chomp                   extract_extradata       h264_redundant_pps      imx_dump_header         mp3_header_decompress   null                    trace_headers           vp9_superframe

Enabled indevs:
alsa                    fbdev                   lavfi                   oss                     v4l2                    xcbgrab

Enabled outdevs:
alsa                    fbdev                   oss                     sdl2                    v4l2                    xv

License: LGPL version 2.1 or later
⏳ Configuring dynamic linker configuration ...
 Updating dynamic linker run-time bindings and library cache ...
⏳ Add FFmpeg to libarry path of Firefox ...
eadams@eadams-proxy~/Downloads $ ll /opt
total 24
drwxr-xr-x  6 root root 4096 Jul 24 14:09 .
drwxr-xr-x 20 root root 4096 Jul 24 14:09 ..
drwxr-xr-x  3 root root 4096 Feb 13  2019 bin
drwxr-xr-x  3 root root 4096 Jul 24 14:09 cni
drwx--x--x  4 root root 4096 Mar  6  2019 containerd
drwxr-xr-x 13 root root 4096 Jan 29  2018 VirtualBox

I will take a look.
Actually I should have told you that now you don’t need sudo to execute the script. It will ask for root privilege when it’s needed.

Thanks. I did retry by deleting the git repo so it would force it to download again and using ./install and no luck. I did try on two different clear linux installs.

It’ the same on my side. I will try to build and install it manually :smile:

I’ll update my script, and fix the problem.

I’ve done it manually like described here: How-to: h264 etc. Support for Firefox (including ffmpeg install) and it is working for me.

What I’ve noticed are different directories to your script. Maybe that the point?

§ cat /etc/
include /etc/*.conf

$ cat firefox.conf 
export LD_LIBRARY_PATH=/usr/local/lib

FFMpeg Conf is here:

Nah, that’s not the cause.
I’ve fixed the bug now.

I’ve fixed the bug now.
So the mistake was

! A && B && C

and it should be

! A || ! B || ! C

Nice job. I just tried the script again and was able to play an h.264 video in my browser once I restarted Firefox.

1 Like