关于raspberry-pi:树莓派aarch64编译静态的ffmpeg-可硬解h264hevc

73次阅读

共计 6410 个字符,预计需要花费 17 分钟才能阅读完成。

  • 零碎 openfans aarch64
  • 树莓派 4B
  • docker

此办法特点

  • 不净化现有的零碎(编译在 docker 中), 因为各种依赖库会占用掉 2G 左右空间。

    没有洁癖的能够参考作者上一篇文章: aarch64 零碎 编译最新的 ffmpeg 并反对硬解 h264

  • 编译进去的文件是动态的, 也就是 无需装置任何依赖 就能够运行在 aarch64 零碎上
  • 反对 h264_v4l2m2m 的 GPU 硬解输入, CPU 占用极低, 解码速度也很快.
  • 如果应用同样的参数用 CPU 解码, 4 核 CPU 均在 40%~60% 左右, 而 v4l2m2m 只须要 1 核的 20% 省下很大的 CPU 用量
  • 在 640×480 的分辨率下, 上传至 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 零碎上就能够间接运行

正文完
 0