Android 编译 FFMPEG 7.0.2 + x264错误排查.
1.使用android-ndk-r23c来编译FFMPEG 和X264,提示X264找不到.
1 | **ERROR: x264 not found using pkg-config** |
参考Chat-gpt 的回答,需要安装pkg-config,并且export PKG_CONFIG_PATH=/xxx/x264
安装后,在命令行里手工验证是ok的.
1 | ubuntu:/work/ThirdParty/ffmpeg4$ export PKG_CONFIG_PATH=$(pwd)/dist/x264/arm64-v8a/lib/pkgconfig/ |
但是编译时仍然报错. 查看FFMPEG的configurate 日志ffbuild/config.log
1 | require_pkg_config libx264 x264 stdint.h x264.h x264_encoder_encode |
发现是shell函数test_pkg_config报的错.
1 |
|
那么就是$pkg_config 值有问题了, 从上面的log看,值应该是false.
在config.log也有一行警告:
WARNING: /home/Android/android-ndk-r23c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-pkg-config not found, library detection may fail.
可以看出系统是找交叉编译的aarch64-linux-android-pkg-config.
而NDK并未提供. 实际上也不需要交叉编译的这个工具,因为只是读取文本的配置文件,跟平台无关,因此可以直接设置使用宿主的pkg-config命令.
在configurate的参数中指定即可.
1 | ./configure --pkg-config=pkg-config |
2.编译出FFMPEG和x264的静态库之后,再跟业务项目联编的时候,报错-fPIC.
1 | ld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol ff_tx_tab_32_float; recompile with -fPIC |
参考 https://ffmpeg.org/platform.html#toc-Advanced-linking-configuration
1.1 Advanced linking configuration
If you compiled FFmpeg libraries statically and you want to use them to build your own shared library, you may need to force PIC support (with --enable-pic
during FFmpeg configure) and add the following option to your project LDFLAGS:
- -
Wl,-Bsymbolic
需要在configurate 指定--enable-pic
,并且在自己的工程里增加 -Wl,-Bsymbolic
.
还有去掉ffmpeg其他地方指定的-fPIC参数.