本文所在系统环境ubuntu18.04
交叉编译工具链gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu
ffmpeg版本5.0.1
1.下载源码
ffmpeg官网:https://ffmpeg.org/download.html#build-linux
下载完解压
2.安装依赖
sudo apt-get install libmp3lame-dev libx264-dev libxvidcore-dev
sudo apt-get update && sudo apt-get -y install \
autoconf \
automake \
build-essential \
cmake \
git-core \
libass-dev \
libfreetype6-dev \
libgnutls28-dev \
libmp3lame-dev \
libsdl2-dev \
libtool \
libva-dev \
libvdpau-dev \
libvorbis-dev \
libxcb1-dev \
libxcb-shm0-dev \
libxcb-xfixes0-dev \
meson \
ninja-build \
pkg-config \
texinfo \
wget \
yasm \
zlib1g-dev \
libunistring-dev
3.生成
进入ffmpeg源码文件中打开终端,记得修改最终生成路径--prefix,交叉编译工具链路径--cross-prefix,以及aarch64-linux-gnu-gcc与aarch64-linux-gnu-g++所在路径--cc、--cxx
chmod +x configure
./configure --enable-cross-compile --target-os=linux --arch=arm64 \
--cross-prefix=/home/fy/gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- \
--cc=/home/fy/gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc \
--cxx=/home/fy/gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ \
--prefix=/home/fy/LIBS/ffmpeg5.0.1_linux_arm64 \
--disable-asm --enable-parsers --disable-decoders --enable-decoder=h264 --enable-decoder=aac --disable-debug --enable-ffmpeg --enable-shared --disable-static --disable-stripping --disable-doc
4.编译
需要sudo自己加
make -j$(nproc)
如果出现xxx权限不够,使用chmod加执行权限
sudo chmod -R 777 ./
5.安装
需要sudo自己加
make install
6.交叉编译带libx264的ffmpeg库(可选,结合上面的步骤看)
下载libx264,x264, the best H.264/AVC encoder - VideoLAN
在ubuntu解压,编译方法为
./configure --cross-prefix=/opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- \
--host=aarch64-linux \
--prefix=/home/fy/x264lib \
--enable-shared --disable-asm
make -j$(nproc)
make install
注意修改自己交叉编译链路径--cross-prefix,目标路径--prefix,--host
再编译ffmpeg的选项如下
./configure --enable-cross-compile --target-os=linux --arch=aarch64 \
--cross-prefix=/opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- \
--cc=/opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc \
--cxx=/opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ \
--prefix=/home/fy/ffmpeg5.0.1_build \
--disable-asm --enable-parsers --enable-decoder=h264 --enable-decoder=aac --disable-debug --enable-ffmpeg --enable-shared --disable-static --disable-stripping --disable-doc --enable-gpl --enable-swresample --enable-libx264 \
--extra-libs=-ldl \
--extra-cflags="-I/home/fy/ffmpeg5.0.1/x264lib/include" \
--extra-ldflags="-L/home/fy/ffmpeg5.0.1/x264lib/lib"