ijkplayer(一)- iOS集成

git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-ios
cd ijkplayer-ios
git checkout -B latest k0.8.8
 //初始化,会把ffmpeg的代码拉取到本地./init-ios.sh
./init-ios.sh
./init-ios-openssl.sh
cd iOS

   //预编译先,先vim一下module脚本
  vim ../config/module.sh

  //添加预编译脚本内容为一下内容,然后点击 esc 退出 vim编译模式,执行 :wq 保存
  export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-openssl"

  // 先clean一下FFmpeg相关的数据,避免在执行all时出现新旧数据冲突
  ./compile-openssl.sh clean
  ./compile-ffmpeg.sh clean

 //编译ffmpeg软解码库,这个过程会生成各种架构的ffmpeg,编译ffmpeg前要先compile OpenSSL,对openssl进行编译,如果未执行可能会报错:openssl not found
  ./compile-openssl.sh all
  ./compile-ffmpeg.sh all

编译完成后,打开IJKMediaPlayer选中其中的IJKMediaFramework,修改工程配置中的bitCode配置为NO。注意Release模式。
编译成功后即可得到支持https的framework。

1.执行./compile-ffmpeg.sh all时遇到

xcrun -sdk iphoneos clang is unable to create an executable file.C compiler test failed.If you think configure made a mistake, make sure you are using the latestversion from Git.Ifthe latest version fails, report the problem to [email protected] mailinglistorIRC#ffmpeg on irc.freenode.net.Includethe log file"config.log"produced by configureasthis will helpsolve the problem.

解决办法:
执行以下命令

sudo xcode-select --switch /Applications/Xcode.app

之后再次执行

./compile-ffmpeg.sh clean
./compile-ffmpeg.sh all

2.再次执行./compile-ffmpeg.sh all时遇到

./libavutil/arm/asm.S:50:9: error: unknown directive
.arch armv7-a
^
make: *** [libavcodec/arm/aacpsdsp_neon.o] Error 1
make: *** Waiting for unfinished jobs....

注意:网上的说法几乎都是建议在 compile-ffmpeg.sh 中删除 armv7,修改为:
FF_ALL_ARCHS_IOS8_SDK="arm64 i386 x86_64"
然后再编译。
但这样在之后lipo合并的库中就没有armv7版本了,所以在xcode项目的Valid Architectures里就要去掉armv7,否则会报错。
实际上还有另一种方法,即禁用汇编,将ios/tools/do-compile-ffmpeg.sh文件里的armv7架构的情况,改为:

elif [ "$FF_ARCH" = "armv7" ]; then
    FF_BUILD_NAME="ffmpeg-armv7"
    FF_BUILD_NAME_OPENSSL=openssl-armv7
    FF_XCRUN_OSVERSION="-miphoneos-version-min=6.0"
    FF_XCODE_BITCODE="-fembed-bitcode"
    FFMPEG_CFG_FLAGS="$FFMPEG_CFG_FLAGS --enable-pic --disable-asm"

之后再次执行

./compile-ffmpeg.sh clean
./compile-ffmpeg.sh all

这样就能编译出包含armv7架构的库了。

3.导入项目实战

由于ijkplayer本身默认不支持https,因此在预编译FFmpeg和openssl时,工程的 ijkplayer-ios/ios/build/universal/lib 路径下会生成如下的.a静态包:
但是IJKMediaPlayer这个framework工程中,默认是不导入libcrypto.a和libssl.a文件的,而这两个文件恰恰是ijkplayer编译支持https的关键
打开 IJKMediaPlayer工程
进入 Build Phases -> Link Binary With Libraries
点击 “+”号 -> Add Other
添加 ijkPlayer-ios/ios/build/universal/lib 路径下的 libcrypto.a 和 libssl.a文件到 IJKMediaPlayer这个framework工程中

第一步:打开demo


WeChat28e422a464aca8a56087961261c7b27b.png

第二步:选择真机 和 模拟器进行编译!


[图片上传中...(截屏2021-08-04 下午3.28.31.png-26ecad-1628062147602-0)]

第三步:打开编译好的文件查看


截屏2021-08-04 下午3.28.31.png

第四步:编译产生的文件

WeChat09ed69e93dfcd81b887fd0330538a343.png

第六步:合并文件并将合成的文件 与 真机环境的文件内容进行替换


WeChatae0835b833756071c0da54653ee5b648.png
WeChat88e4db6fb487d52b510e6389885f94a9.png

运行下面代码 两者文件合并为一个新的文件,新的文件同时兼容了真机和模拟器
lipo -create Release-iphoneos/IJKMediaFramework.framework/IJKMediaFramework Release-iphonesimulator/IJKMediaFramework.framework/IJKMediaFramework -output IJKMediaFramework

你可能感兴趣的:(ijkplayer(一)- iOS集成)