• System openfans aarch64
  • Raspberry sent 4 b
  • docker

Characteristics of this method

  • Does not pollute the existing system (compiled in Docker), as the various dependent libraries take up around 2G of space.

    For those who are not squeamish, please refer to the author’s last article:
    The AARCH64 system compiles the latest FFMPEG and supports hard solution H264

  • The compiled file is static, which means it can run on the aarch64 system without installing any dependencies
  • Support H264_V4L2M2M GPU hard solution output, CPU consumption is very low, the decoding speed is very fast.
  • If the same parameters are used to decode with CPU, the 4-core CPU is about 40%~60%, while V4L2M2M only needs 20% of 1 core, which saves a lot of CPU consumption
  • Under the resolution of 640×480, upload to RTSP live broadcast server, use POTPlayer to play, the delay is about 200ms, basically called synchronization
  • Solved the V4L2M2M2 black screen BUGThis is a problem with direct compilation in Git.https://johnvansickle.com/ffmpeg/Static files downloaded also have this BUG

compile

Start Ubuntu’s clean container

docker run -u root -it --privileged -v /dev/:/dev/ ubuntu bash

The script

To be on the safe side, you need to paste it block by block to the console to execute

The main problem is that part of the file network is not accessible, so you need to set up your own proxy
export https_proxy=http://your.proxy. ip:port

apt update
apt install -y ca-certificates

export DEBIAN_FRONTEND=noninteractive
cp /etc/apt/sources.list /etc/apt/sources.list.bak
echo -e 'deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse\ndeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse\ndeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse\ndeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse' > /etc/apt/sources.list

apt update
apt install -y build-essential cmake meson sudo pkg-config autopoint automake libtool
apt install -y libxvidcore-dev git wget

cd ~

git clone --depth 1 --branch n4.4 https://github.com/FFmpeg/FFmpeg.git
cd FFmpeg
wget https://dl.dropboxusercontent.com/s/eja8vz5jh1felnp/patch.diff
git apply patch.diff
cd ~

git clone --depth 1 https://github.com/madler/zlib.git
mkdir ~/zlib/build
cd ~/zlib/build
cmake -DBUILD_SHARED_LIBS=OFF ..
make -j$(nproc)
make install
cd ~

git clone --depth 1 https://github.com/LuaDist/bzip2.git
mkdir ~/bzip2/build
cd ~/bzip2/build
cmake -DBUILD_SHARED_LIBS=OFF ..
make -j$(nproc)
make install
cd ~


git clone --depth 1 https://github.com/kobolabs/liblzma.git
cd liblzma
./configure --enable-shared --enable-static
make -j$(nproc)
make install
cd ~

wget https://gmplib.org/download/gmp/gmp-6.2.1.tar.xz
tar xvf gmp-6.2.1.tar.xz
cd gmp-6.2.1
./configure --enable-shared --enable-static
make -j$(nproc)
make install
cd ~

git clone --depth 1 https://github.com/LuaDist/libjpeg.git
mkdir ~/libjpeg/build
cd ~/libjpeg/build
cmake -DBUILD_SHARED_LIBS=OFF ..
make -j$(nproc)
make install
cd ~

git clone --depth 1 https://github.com/uclouvain/openjpeg.git
mkdir ~/openjpeg/build
cd ~/openjpeg/build
cmake -DBUILD_SHARED_LIBS=OFF ..
make -j$(nproc)
make install
mkdir ~/openjpeg/build1
cd ~/openjpeg/build1
cmake -DBUILD_SHARED_LIBS=ON ..
make -j$(nproc)
make install
cd ~

git clone --depth 1 https://github.com/glennrp/libpng.git
cd libpng
./autogen.sh
./configure --enable-shared --enable-static
make -j$(nproc)
make install
cd ~

git clone --depth 1 https://github.com/mirrorer/giflib.git
cd giflib
./autogen.sh
./configure --enable-shared --enable-static
make -j$(nproc)
make install
cd ~

wget https://www.openssl.org/source/openssl-1.1.1-latest.tar.gz
tar -zxvf openssl-*-latest.tar.gz
cd `ls -d */ | cut -f1 -d'/' | grep openssl`
./config --prefix=/usr
make -j$(nproc)
make install_sw install_ssldirs
cd ~

git clone --depth 1 https://github.com/GNOME/libxml2.git
cd libxml2
./autogen.sh
./configure --enable-shared --enable-static
make -j$(nproc)
make install
cd ~

git clone --depth 1 https://github.com/raspberrypi/userland ~/userland
cd userland
./buildme --aarch64
cd ~


git clone --depth 1 https://code.videolan.org/videolan/dav1d.git
mkdir ~/dav1d/build
cd ~/dav1d/build
meson -Ddefault_library=static ..
ninja -j$(nproc)
ninja install
cd ~

git clone --depth 1 https://github.com/mstorsjo/fdk-aac.git
cd fdk-aac
./autogen.sh
./configure --enable-shared --enable-static
make -j$(nproc)
make install
cd ~

wget https://johnvansickle.com/ffmpeg/release-source/freetype-2.6.1.tar.xz
tar xvf freetype-2.6.1.tar.xz
cd freetype-2.6.1
./autogen.sh
./configure --enable-shared --enable-static
make -j$(nproc)
make install
cd ~

git clone --depth 1 https://github.com/ultravideo/kvazaar.git
cd kvazaar
./autogen.sh
./configure --enable-shared --enable-static
make -j$(nproc)
make install
cd ~

wget https://johnvansickle.com/ffmpeg/release-source/lame-3.99.5.tar.xz
tar xvf lame-3.99.5.tar.xz
cd lame-3.99.5
./configure --build=arm-linux --enable-shared --enable-static
make -j$(nproc)
make install
cd ~

git clone --depth 1 https://github.com/webmproject/libwebp.git
cd libwebp
./autogen.sh
./configure --enable-shared --enable-static
make -j$(nproc)
make install
cd ~

git clone --depth 1 https://github.com/mirror/x264.git
cd x264
./configure --enable-shared --enable-static --disable-opencl --enable-pic
make -j$(nproc)
make install-lib-static
cd ~

git clone --depth 1 https://github.com/videolan/x265.git
cd x265/build/aarch64-linux
cmake -DCMAKE_TOOLCHAIN_FILE="crosscompile.cmake" -G "Unix Makefiles" -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK_CRT:BOOL=ON -DENABLE_CLI:BOOL=OFF ../../source
make -j$(nproc)
make install
cd ~

wget https://johnvansickle.com/ffmpeg/release-source/opencore-amr-0.1.3.tar.xz
tar xvf opencore-amr-0.1.3.tar.xz
cd opencore-amr-0.1.3
./configure --enable-shared --enable-static
make -j$(nproc)
make install
cd ~

git clone --depth 1 https://github.com/webmproject/libvpx.git
cd libvpx
./configure --disable-examples --disable-tools --disable-unit_tests --disable-docs --enable-shared --enable-static
make -j$(nproc)
make install
cd ~

git clone --depth 1 https://github.com/sekrit-twc/zimg.git
cd zimg
sh autogen.sh
./configure  --enable-shared --enable-static
make -j$(nproc)
make install
cd ~

wget https://johnvansickle.com/ffmpeg/release-source/frei0r-plugins-1.4.tar.xz
tar xvf frei0r-plugins-1.4.tar.xz
mkdir ~/frei0r-plugins-1.4/build
cd ~/frei0r-plugins-1.4/build
cmake -DBUILD_SHARED_LIBS=OFF ..
./configure --enable-shared --enable-static
make -j$(nproc)
make install
cd ~

git clone --depth 1 https://github.com/xiph/opus.git
cd opus
./autogen.sh
./configure --enable-shared --enable-static
make -j$(nproc)
make install
cd ~


cd FFmpeg
./configure \
--extra-cflags="-I/usr/local/include" \
--extra-ldflags="-L/usr/local/lib -L/usr/lib/aarch64-linux-gnu/" \
--pkg-config-flags="--static" \
--extra-libs="-lpthread -lm -lz -lx265" \
--extra-ldexeflags="-static" \
--enable-neon \
--enable-hwaccels \
--enable-version3 \
--enable-gpl \
--disable-shared \
--enable-static \
--disable-debug \
--disable-ffplay \
--disable-indev=sndio \
--disable-outdev=sndio \
--enable-frei0r \
--enable-gmp \
--enable-gray \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libopencore-amrnb \
--enable-libopencore-amrwb \
--enable-libopus \
--enable-libopenjpeg \
--enable-libkvazaar \
--enable-libvpx \
--enable-libwebp \
--enable-libx264 \
--enable-libxml2 \
--enable-libdav1d \
--enable-libxvid \
--enable-nonfree \
--enable-libzimg \
--enable-libxml2 \
--enable-openssl \
--enable-omx \
--enable-omx-rpi \
--enable-hardcoded-tables

make -j$(nproc)

It is impossible to compile a static execution file without these two parameters

The author also tried to test various methods, compiled no less than 10 times to produce a static file (compiled once 20~30 minutes)

--pkg-config-flags="--static" \
--extra-ldexeflags="-static" \

Generated file

The FFmpeg under ~/FFmpeg is a static executable file, which can be copied to the aarch64 system and run directly