[树莓派]aarch64编译静态的ffmpeg 可硬解h264/hevc

member
English
  • 系统 openfans aarch64
  • 树莓派4B
  • docker

此方法特点

  • 不污染现有的系统(编译在docker中), 因为各种依赖库会占用掉2G左右空间。

    没有洁癖的可以参考作者上一篇文章: aarch64 系统 编译最新的ffmpeg 并支持硬解h264
  • 编译出来的文件是静态的, 也就是无需安装任何依赖就可以运行在aarch64系统上
  • 支持h264_v4l2m2m的GPU硬解输出, CPU占用极低, 解码速度也很快.
  • 如果使用同样的参数用CPU解码, 4核CPU均在40%~60%左右, 而v4l2m2m只需要1核的20% 省下很大的CPU用量
  • 在640x480的分辨率下, 上传至rtsp直播服务器端, 使用potplayer播放, 延时在200ms左右, 基本上叫同步
  • 解决了v4l2m2m2黑屏的BUG, 原git里面直接编译就有这个问题, https://johnvansickle.com/ffmpeg/下载的静态文件也有此BUG

编译

启动ubuntu干净的容器

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

脚本

为了保险起见, 需要一个块一个块的贴到控制台去执行

主要问题是部分文件网络无法访问, 需要自行设置代理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)

关键参数
没有这2个参数是无法编译出静态执行文件的

作者也是尝试了试验了各种方法, 编译不下10次才制作出静态文件(编译一次20~30余分钟)
--pkg-config-flags="--static" \
--extra-ldexeflags="-static" \

生成的文件

~/FFmpeg下的ffmpeg就是静态的可执行文件, 复制到aarch64系统上就可以直接运行

阅读 1.6k

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

6.1k 声望
151 粉丝
0 条评论

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

6.1k 声望
151 粉丝
文章目录
宣传栏