Bash Script to Add H.264 Support for Firefox

I made this script based on this post: https://community.clearlinux.org/t/how-to-h264-etc-support-for-firefox-including-ffmpeg-install

To run it, execute the following in terminal

sudo ./install.bash

When I got time, I will publish it to GitHub and write a README. For now, you can just read the source code.

#!/usr/bin/env bash

## References:
## https://community.clearlinux.org/t/how-to-h264-etc-support-for-firefox-including-ffmpeg-install

## Make sure to have root privilege
if [ "$(whoami)" != 'root' ]; then
  echo -e "\e[31m\xe2\x9d\x8c Please retry with root privilege.\e[m"
  exit 1
fi

## Install dependencies
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 pull
else
  git clone https://github.com/FFmpeg/FFmpeg
  # shellcheck disable=SC2164
  cd FFmpeg
fi

## 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 | grep 'n' | grep -v 'dev' | 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
echo
if ! ./configure --prefix=/opt/ffmpeg --enable-shared && make && make install; then
  echo -e "\e[31m Installation failed! Aborting...\e[m"
  exit 1
fi

## 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/ld.so.conf ] || [ "$(grep 'include /etc/ld\.so\.conf\.d/\*\.conf' /etc/ld.so.conf )" = '' ]; then
  cat <<EOF >> /etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf
EOF
fi
if [ ! -d /etc/ld.so.conf.d ]; then
  mkdir /etc/ld.so.conf.d
fi
cat <<EOF > /etc/ld.so.conf.d/ffmpeg.conf
/opt/ffmpeg/lib
EOF
echo -e "\e[32m Updating dynamic linker run-time bindings and library cache ...\e[m"
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 'export LD_LIBRARY_PATH)' "${HOME}/.config/firefox.conf")" = '' ]; then
  echo "export LD_LIBRARY_PATH=/opt/ffmpeg/lib" >> "${HOME}/.config/firefox.conf"
else
  sed -i 's#export LD_LIBRARY_PATH=#&/opt/ffmpeg/lib;#'
fi

You can download it here.

4 Likes

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 ...
/opt/ffmpeg/lib
 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.