1
  • System openfans aarch64
  • Raspberry Pi 4B
  • docker

Features of this method

  • Does not pollute the existing system (compiled in docker), because various dependent libraries will take up about 2G of space.

    who are not clean can refer to the author's previous article: 160bcc6e1a3e6b aarch64 system compiles the latest ffmpeg and supports hard decoding of h264
  • The compiled file is static, that is, can run on the aarch64 system without installing any dependencies
  • Supports GPU hardware decoding output of h264_v4l2m2m, the CPU usage is extremely low, and the decoding speed is also very fast.
  • If you use the same parameters to decode with the CPU, the 4-core CPU is about 40%~60%, and v4l2m2m only needs 20% of the 1 core, which saves a lot of CPU usage
  • At a resolution of 640x480, upload to the rtsp live server side, use potplayer to play, the delay is about 200ms, basically called synchronization
  • solves the black screen bug of , the direct compilation in the original git has this problem, the static file downloaded by https://johnvansickle.com/ffmpeg/

Compile

Start ubuntu clean container

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

script

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

The main problem is that some files cannot be accessed from the network, so you need to set up a 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)

key parameter
Without these 2 parameters, it is impossible to compile a static executable file.

The author also tried various methods, compiled no less than 10 times before making a static file (compiled once for more than 20 to 30 minutes)
--pkg-config-flags="--static" \
--extra-ldexeflags="-static" \

Generated file

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


member
6.2k 声望158 粉丝

擅长计算机开关机、Windows系统的安装。