Compile FFmpeg5.0 64-bit version based on NDK 24 under Ubuntu 20

foreword

This article is a summary of some methods and pit records when I compiled FFmpeg. There are more or less problems with the compilation scripts used in many tutorials on the Internet. I mainly make some optimizations on the basis of the predecessors. Questions are welcome to discuss

Environment configuration

I won't say much about this.
Operating system: Ubuntu 20.04.4
NDK r24
FFmpeg 5.0
ndk I downloaded it directly through Android studio, or it can be downloaded separately.
Next, I need to configure the NDK environment. This is also relatively simple, but I will go into details.

vim etc/profile
#输入你自己的ndk路径
export NDK_HOME=/Android/Sdk/ndk/24.0.8215888
复制代码

test:

ndk-build -v
复制代码

The following prompt appears to indicate success:

20220408104816.pngIf unsuccessful, you may need to give folder permissions:

chmod 751 -r 目录名称
复制代码

Compile FFmpeg

Go to the official website to download version 5.0, unzip it, and give permission to change the directory. After that, we start to write the compilation script
. Execute the command:

vim ffbuild.sh
复制代码

Enter the following:

#!/bin/bash

#此处 NDK_HOME 为环境变量
#我的路径是 /Android/Sdk/ndk/24.0.8215888
NDK_ROOT=$NDK_HOME

echo "<<<<<<<<<<<<<基于NDK24编译 FFmpeg 5.0 64位硬件解码版本>>>>>>>>>>>>>>"

#设置编译平台的相关参数
CPU=armv8-a
ARCH=arm64
OS=android
PLATFORM=aarch64-linux-android
OPTIMIZE_CFLAGS="-march=$CPU"


#指定输出路径
PREFIX=$(pwd)/android/aarch64
#此处 TOOLCHAIN 为环境变量
#我的路径是 /Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64
SYSROOT=$TOOLCHAIN/sysroot
CROSS_PREFIX=$TOOLCHAIN/bin/llvm-
#CROSS_PREFIX=$TOOLCHAIN/bin/$PLATFORM-
ANDROID_CROSS_PREFIX=$TOOLCHAIN/bin/${PLATFORM}21-


echo "开始编译 $CPU"
#该脚本命令中不能插入注释,每行命令必须以 \ 结尾
./configure \
--prefix=$PREFIX \
--enable-shared \
--enable-gpl \
--enable-neon \
--enable-hwaccels \
--enable-postproc \
--enable-jni \
--enable-small \
--enable-mediacodec \
--enable-decoder=h264_mediacodec \
--enable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffplay \
--disable-avdevice \
--disable-debug \
--disable-static \
--disable-doc \
--disable-symver \
--cross-prefix=$CROSS_PREFIX \
--target-os=$OS \
--arch=$ARCH \
--cpu=$CPU \
--cc=${ANDROID_CROSS_PREFIX}clang \
--cxx=${ANDROID_CROSS_PREFIX}clang++ \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fPIC $OPTIMIZE_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \

make clean
#编译
make
#安装
make install

echo "编译完成 $CPU"
复制代码

Before using it, you need to change the path specified by the script to your own ndk path. After that, it is best to ensure that gcc and yasm have been installed on your system (the installed ones can be ignored), and execute the following command:

#更新
sudo apt-get update
#安装工具包
sudo apt-get install yasm 
sudo apt-get install build-essential
复制代码

The following are some notes about the script:
1. The path needs to be changed to the path under your own ndk.
2. The configuration parameters of ./configure can be set according to your own needs. Specifically, you can click on the folder after ffmpeg is decompressed. 3. If you
need to compile the 32-bit version, change the corresponding parameters

ARCH=arm 
CPU=armv7-a 
PLATFORM=armv7a-linux-androideabi
PREFIX=$(pwd)/android/$CPU 
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "
复制代码

execute script

Put the script in the ffmpeg directory and run the command to execute

sh ffbuild.sh
复制代码

Then it will start to compile ffmpeg

Pits encountered during compilation

1、xxxx-clang is unable to create an executable file.

20220408114232.png
This is usually a path problem, be sure to double check whether the path configuration is correct

2. -- XX command: not found

20220408114654.png
Check if the command in the script \ends with , or if there are other useless characters in the command
3, ./configre: xxxxxxx-nm not found or xxxx-strip not found, etc.

20220408115058.png

20220408120018.pngWhen something like the above appears, we can observe that there is no corresponding tool in the path it prints, but we can find llvmtools with prefixes in the directory, such as llvm-nm, llvm-stripetc. The prefixes of these tools are specified by the --cross-prefix=command . Many scripts on the Internet use prefixes such as armv7a-linux-android, which must not be found. This should be the practice of the previous version, so I changed it to this in the compilation script I gave $TOOLCHAIN/bin/llvm-, so there is no problem. .
Of course, if so-and-so not found still appears, we can also specify the path for the tool separately,
such as xxx-strip not found, we can add an instruction to specify the path of the strip tool, as follows:

STRIP=$TOOLCHAIN/bin/bin/llvm-strip
./configure \
.... \
--strip=$STRIP \
复制代码

Summarize

This article is just some changes and optimizations made on the basis of the predecessors and some pit records. If you need a more detailed introduction, you can go to the big guy's # One-click compilation of 32/64-bit FFmpeg 4.2.2

Guess you like

Origin juejin.im/post/7084122050456977444