FFmpeg的编译就不说了,网上有很多的shell脚本,可以自己下载一个,根据自己的需求改一改。关于iOS编译FFmpeg库的脚本到GitHub上下载。脚本的地址:[https://github.com/kewlbear/FFmpeg-iOS-build-script]
在学习这个库的时候遇到的Xcode编译问题 (Xcode9.1)
- 问题1 因为导入系统库 Xcode9.1 不是自动帮你连接到项目中的,如果你导入.a库,在编译的时候,报如下的错误:
Undefined symbols for architecture arm64:
"_iconv", referenced from:
_avcodec_decode_subtitle2 in libavcodec.a(decode.o)
"_iconv_open", referenced from:
_avcodec_open2 in libavcodec.a(utils.o)
_avcodec_decode_subtitle2 in libavcodec.a(decode.o)
"_iconv_close", referenced from:
_avcodec_open2 in libavcodec.a(utils.o)
_avcodec_decode_subtitle2 in libavcodec.a(decode.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
解决办法,下图所示 👇
- 问题2 当使用
av_register_all()
函数的时候报了如下的错误:
Undefined symbols for architecture arm64:
"_CMTimeMake", referenced from:
_vtenc_send_frame in libavcodec.a(videotoolboxenc.o)
"_kCMTimeInvalid", referenced from:
_vtenc_send_frame in libavcodec.a(videotoolboxenc.o)
"_CMSampleBufferGetSampleAttachmentsArray", referenced from:
_vtenc_frame in libavcodec.a(videotoolboxenc.o)
"_kCMSampleAttachmentKey_NotSync", referenced from:
_vtenc_frame in libavcodec.a(videotoolboxenc.o)
"_CMSampleBufferGetFormatDescription", referenced from:
_vtenc_frame in libavcodec.a(videotoolboxenc.o)
_vtenc_output_callback in libavcodec.a(videotoolboxenc.o)
"_CMBlockBufferCopyDataBytes", referenced from:
_vtenc_frame in libavcodec.a(videotoolboxenc.o)
"_CMVideoFormatDescriptionGetH264ParameterSetAtIndex", referenced from:
_vtenc_frame in libavcodec.a(videotoolboxenc.o)
_get_params_size in libavcodec.a(videotoolboxenc.o)
_copy_param_sets in libavcodec.a(videotoolboxenc.o)
"_CMSampleBufferGetPresentationTimeStamp", referenced from:
_vtenc_frame in libavcodec.a(videotoolboxenc.o)
"_CMSampleBufferGetTotalSampleSize", referenced from:
_vtenc_frame in libavcodec.a(videotoolboxenc.o)
"_CMBlockBufferCreateWithMemoryBlock", referenced from:
_videotoolbox_common_end_frame in libavcodec.a(videotoolbox.o)
"_CMSampleBufferGetDataBuffer", referenced from:
_vtenc_frame in libavcodec.a(videotoolboxenc.o)
"_kCMTimeIndefinite", referenced from:
_vtenc_init in libavcodec.a(videotoolboxenc.o)
_vtenc_frame in libavcodec.a(videotoolboxenc.o)
_vtenc_close in libavcodec.a(videotoolboxenc.o)
"_CMSampleBufferCreate", referenced from:
_videotoolbox_common_end_frame in libavcodec.a(videotoolbox.o)
"_kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms", referenced from:
_videotoolbox_default_init in libavcodec.a(videotoolbox.o)
"_CMSampleBufferGetDecodeTimeStamp", referenced from:
_vtenc_frame in libavcodec.a(videotoolboxenc.o)
"_CMVideoFormatDescriptionCreate", referenced from:
_videotoolbox_default_init in libavcodec.a(videotoolbox.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
解决办法
- 第一:将报错信息里面的
系统库
VideoToolbox.framework
导入项目中,别忘了手动链接(Xcode9 不是自动帮你链接的,链接方法跟问题1的链接方法一样) - 第二:在用到
av_register_all()
函数地方导入VideoToolbox.framework
的头文件 - 注意:如果报错的信息是AudioToolbox... ,那么就需要导入
AudioToolbox.framework
, 导入#import<AudioToolbox/AudioToolbox.h>
如下所示👇