Skip to content

Instantly share code, notes, and snippets.

@wildrun0
Last active March 25, 2024 09:21
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 16 You must be signed in to fork a gist
  • Save wildrun0/86a890585857a36c90110cee275c45fd to your computer and use it in GitHub Desktop.
Save wildrun0/86a890585857a36c90110cee275c45fd to your computer and use it in GitHub Desktop.
Compiling ffmpeg for Raspberry Pi 4 (script only works fine on RPi OS 32bit). x64 does not support mmal (see https://github.com/raspberrypi/userland/issues/688)
#!/bin/bash
# Note that there's no libdrm because this lib cause errors
sudo apt update -y && sudo apt upgrade -y
sudo apt-get -y install \
autoconf \
automake \
build-essential \
cmake \
doxygen \
git \
graphviz \
imagemagick \
libasound2-dev \
libass-dev \
libavcodec-dev \
libavdevice-dev \
libavfilter-dev \
libavformat-dev \
libavutil-dev \
libfreetype6-dev \
libgmp-dev \
libmp3lame-dev \
libopencore-amrnb-dev \
libopencore-amrwb-dev \
libopus-dev \
librtmp-dev \
libsdl2-dev \
libsdl2-image-dev \
libsdl2-mixer-dev \
libsdl2-net-dev \
libsdl2-ttf-dev \
libsnappy-dev \
libsoxr-dev \
libssh-dev \
libssl-dev \
libtool \
libv4l-dev \
libva-dev \
libvdpau-dev \
libvo-amrwbenc-dev \
libvorbis-dev \
libwebp-dev \
libx264-dev \
libx265-dev \
libxcb-shape0-dev \
libxcb-shm0-dev \
libxcb-xfixes0-dev \
libxcb1-dev \
libxml2-dev \
lzma-dev \
meson \
nasm \
pkg-config \
python3-dev \
python3-pip \
texinfo \
wget \
yasm \
libsrt-gnutls-dev \
zlib1g-dev
mkdir ~/ffmpeg-libraries
#AAC
git clone --depth 1 https://github.com/mstorsjo/fdk-aac.git ~/ffmpeg-libraries/fdk-aac \
&& cd ~/ffmpeg-libraries/fdk-aac \
&& autoreconf -fiv \
&& ./configure \
&& make -j$(nproc) \
&& sudo make install
#AV1
git clone --depth 1 https://code.videolan.org/videolan/dav1d.git ~/ffmpeg-libraries/dav1d \
&& mkdir ~/ffmpeg-libraries/dav1d/build \
&& cd ~/ffmpeg-libraries/dav1d/build \
&& meson .. \
&& ninja \
&& sudo ninja install
#HEVC
git clone --depth 1 https://github.com/ultravideo/kvazaar.git ~/ffmpeg-libraries/kvazaar \
&& cd ~/ffmpeg-libraries/kvazaar \
&& ./autogen.sh \
&& ./configure \
&& make -j$(nproc) \
&& sudo make install
#VP8 and VP9
git clone --depth 1 https://chromium.googlesource.com/webm/libvpx ~/ffmpeg-libraries/libvpx \
&& cd ~/ffmpeg-libraries/libvpx \
&& ./configure --disable-examples --disable-tools --disable-unit_tests --disable-docs \
&& make -j$(nproc) \
&& sudo make install
#AP1
git clone --depth 1 https://aomedia.googlesource.com/aom ~/ffmpeg-libraries/aom \
&& mkdir ~/ffmpeg-libraries/aom/aom_build \
&& cd ~/ffmpeg-libraries/aom/aom_build \
&& cmake -G "Unix Makefiles" AOM_SRC -DENABLE_NASM=on -DPYTHON_EXECUTABLE="$(which python3)" -DCMAKE_C_FLAGS="-mfpu=vfp -mfloat-abi=hard" .. \
&& sed -i 's/ENABLE_NEON:BOOL=ON/ENABLE_NEON:BOOL=OFF/' CMakeCache.txt \
&& make -j$(nproc) \
&& sudo make install
#zimg
git clone --recursive https://github.com/sekrit-twc/zimg.git ~/ffmpeg-libraries/zimg \
&& cd ~/ffmpeg-libraries/zimg \
&& sh autogen.sh \
&& ./configure \
&& make \
&& sudo make install
sudo ldconfig
git clone --depth 1 https://github.com/FFmpeg/FFmpeg.git ~/FFmpeg \
&& cd ~/FFmpeg \
&& ./configure \
--extra-cflags="-I/usr/local/include" \
--extra-ldflags="-L/usr/local/lib" \
--extra-libs="-lpthread -lm -latomic" \
--arch=armhf \
--enable-gmp \
--enable-gpl \
--enable-libass \
--enable-libdav1d \
--enable-libfdk-aac \
--enable-libfreetype \
--enable-libkvazaar \
--enable-libmp3lame \
--enable-libopencore-amrnb \
--enable-libopencore-amrwb \
--enable-libopus \
--enable-librtmp \
--enable-libsnappy \
--enable-libsoxr \
--enable-libssh \
--enable-libvorbis \
--enable-libvpx \
--enable-libzimg \
--enable-libwebp \
--enable-libx264 \
--enable-libx265 \
--enable-libxml2 \
--enable-mmal \
--enable-nonfree \
--enable-omx \
--enable-omx-rpi \
--enable-version3 \
--target-os=linux \
--enable-pthreads \
--enable-openssl \
--enable-hardcoded-tables \
&& make -j$(nproc) \
&& sudo make install
@SalvaHasan
Copy link

Would it work on RPi 3 B+ running Raspbian Buster?

@wildrun0
Copy link
Author

I haven't tested it on RPi 3 but i think it should work

@watershade
Copy link

Thanks for your contribution. My question is how to change it for 64bit os. I change configure to --arch aarch64 but mmal doesn't work
with error imformation: "ERROR: mmal not found"

@ashishbitm
Copy link

What Ubuntu and ffmpeg version did this work ?
I tried it on latest 20.0.1 and 18.0.5 LTS (both 32 and 64) and it fails
If you have history as which version it worked for you . can you please update /share it here
Thank you for your contribution !

@wildrun0
Copy link
Author

wildrun0 commented Dec 8, 2020

Ubuntu

I haven't tested it on Ubuntu. But this should definately work in Raspberry Pi OS (32bit)

@ashishbitm
Copy link

Thank you much for your reply . I am trying on Raspberry Pi OS (32bit)

@oilytin
Copy link

oilytin commented Dec 23, 2020

is it normal to have errors when compiling the libraries? (Pi 4 buster)

@wildrun0
Copy link
Author

yeah its fine

@TMCsw
Copy link

TMCsw commented Jan 21, 2021

I do see this was asked about before, but can any one point me in the right direction? (works Great on RPiOS32b)
I’m trying to get this to work on a Pi 4b running Ubuntu 20.10 64bit TO use Hardware encoding ( -c:v h264_v4l2m2m)

At the tail of the above (supplied scrip) I get:
gcc is unable to create an executable file.
If gcc is a cross-compiler, use the --enable-cross-compile option.
Only do this if you know what cross compiling means.
C compiler test failed.

If you think configure made a mistake,…
Any help?
TMC.

@outhud
Copy link

outhud commented Mar 4, 2022

Thanks for the script.

I notice you have --arch=armel in the ffmpeg configure. I think you should be able to use --arch=armhf and take advantage of the newer ARM processor in Rpi3B and Rpi4.

@marcos12r
Copy link

got this error
ERROR: zimg >= 2.7.0 not found using pkg-config

@voltflake
Copy link

voltflake commented Jul 21, 2022

zimg compilation can be fixed by adding --recursive argument right after git clone

@voltflake
Copy link

Also sudo apt install libsrt-gnutls-dev fixed ERROR: srt >= 1.2.0 not found using pkg-config if someone had this issue

@cdg123
Copy link

cdg123 commented Jul 27, 2022

I've built ffmpeg before and it took such a long time I was really pleased to stumble on this sadly things were going so well untill the tail end where I got....

Cloning into '/home/chris/FFmpeg'...
remote: Enumerating objects: 7765, done.
remote: Counting objects: 100% (7765/7765), done.
remote: Compressing objects: 100% (6029/6029), done.
remote: Total 7765 (delta 2175), reused 3233 (delta 1446), pack-reused 0
Receiving objects: 100% (7765/7765), 16.32 MiB | 3.94 MiB/s, done.
Resolving deltas: 100% (2175/2175), done.
Updating files: 100% (7827/7827), done.

**ERROR: OpenMAX IL headers from raspberrypi/firmware not found**

I'm using a Pi3 and the O/S build is

PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian

My hardware revision is
Hardware : BCM2835
Revision : a02082
Serial : 0000000032c2bc5b
Model : Raspberry Pi 3 Model B Rev 1.2

Could you find 5 mins to point me in the right direction to help resolve it please?

*** UPDATE:****
In case anyone else has this issue turns out I needed to update the firmware to a more recent one using rpi-updat.

Worked perfectly after that so big thanks for publishing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment