之前有客户提出不想使用FFmpeg静态库,想要使用FFmpeg动态库,说什么怕有侵权的风险!我也是醉了,大部分公司都是用的FFmpeg静态库,它居然要求我们公司提供动态库,没办法,谁叫他是客户。后来在网上找了好多资料都没有关于编译FFmpeg动态库的,只有静态库的,静态库相关资料一抓一大把,但一个动态库资料都没有,所以只能自己尝试改些脚本来尝试编译,皇天不负有心人,既然让我编译过了,不过还是有很多问题,但最后都解决了,这里以ffmpeg3.2.4版本为例,可以自行去下载各版本ffmpeg源码下载
当我们编译静态库时会生成scratch这个文件
然后分别到目录scratch/arm64、armv7 下执行脚本生成ffmpeg arm64的动态库和armv7的动态库,再将两个动态库合并成一个同时支持arm64和armv7的动态库,使用 lipo -create 命令,大工告成!
执行的脚本,不带aarch64目录:
xcrun -sdk iphoneos clang -arch armv7 -mios-version-min=8.0 -O3 -DNDEBUG -fembed-bitcode -fms-extensions -stdlib=libc++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk -dynamiclib -Wl,-headerpad_max_install_names -compatibility_version 1.0.0 ./libavcodec/*.o ./libavdevice/*.o ./libavfilter/*.o ./libavformat/*.o ./libavutil/*.o ./libswresample/*.o ./libswscale/*.o -shared -fPIC-framework Foundation-framework CoreFoundation -framework CoreVideo -frameworkAudioToolbox -frameworkVideoToolbox -framework CoreMedia -framework AVFoundation -o FFmpeg -lbz2 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk/usr/lib/libiconv.tbd -lz -liconv -install_name @rpath/FFmpeg.framework/FFmpeg
需要注意的是/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk是xcode安装目录,而且需要指定安装路径 -install_name @rpath/FFmpeg.framework/FFmpeg 不然项目运行时下载不了该动态库
带aarch64目录:
xcrun -sdk iphoneos clang -arch arm64 -mios-version-min=8.0 -O3 -DNDEBUG -fembed-bitcode -fms-extensions -stdlib=libc++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk -dynamiclib -Wl,-headerpad_max_install_names -compatibility_version 1.0.0 ./libavcodec/*.o ./libavdevice/*.o ./libavfilter/*.o ./libavformat/*.o ./libavutil/*.o ./libavutil/aarch64/*.o ./libswresample/*.o ./libswresample/aarch64/*.o ./libswscale/*.o ./libswscale/aarch64/*.o ./libavcodec/neon/*.o ./libavcodec/aarch64/*.o -shared -fPIC-framework Foundation-framework CoreFoundation -framework CoreVideo -frameworkAudioToolbox -frameworkVideoToolbox -framework CoreMedia -framework AVFoundation -o FFmpeg -lbz2 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk/usr/lib/libiconv.tbd -lz -liconv -install_name @rpath/FFmpeg.framework/FFmpeg