美文网首页
ijkplayer集成

ijkplayer集成

作者: 喝酸奶舔下盖 | 来源:发表于2021-12-02 20:51 被阅读0次

一、环境准备

Mac系统版本:12.0.1 (21A559)
Xcode版本:13.1 (13A1030d)

brew --version
git --version
yasm --version
pkg-config --version

未完成安装的,安装下所缺少的

  • 安装brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • 卸载brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
  • 使用brew安装git
brew install git
  • 使用brew安装 yasm
brew install yasm
  • 使用brew 安装 pkg-config
brew install pkg-config

完成后


二、下载ffmpeg

  1. 克隆仓库到本地
//克隆仓库到指定位置并重命名为ijkplayer-ios
git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-ios
  1. 新增一个本地分支(可选项)
git checkout -B latest k0.8.8
  1. 下载ffmpeg(常见错误见下面错误锦集)
./init-ios.sh
  1. 下载成功后进入ios文件夹
cd ios

三、编译 fffmpeg

./compile-ffmpeg.sh clean
./compile-ffmpeg.sh clean 执行成功
./compile-ffmpeg.sh all 

编译过程中可能会出现 error2

./compile-ffmpeg.sh a执行成功

四、打包framework

  1. 打开ios/IJKMediaPlayer并运行
  2. 调整target


  3. 调整运行模式


  4. 分别编译模拟器和真机
    编译成功之后command + ,前往xcode设置页 👉 Lications 👉 Derived Data 👉 IJKMediaPlayer-xxx 👉 Build 👉 Products

cdProducts文件夹下合并真机和模拟器的framework
执行命令: lipo -create 真机framework路径 模拟器framework路径 -output 合并的文件路径

lipo -create Release-iphoneos/IJKMediaFramework.framework/IJKMediaFramework Release-iphonesimulator/IJKMediaFramework.framework/IJKMediaFramework -output IJKMediaFramework

执行成功后Products文件夹下会生成 IJKMediaFramework

五、集成framework

错误锦集

error1

Cloning into 'ios/ffmpeg-x86_64'...
fatal: unable to access 'https://github.com/Bilibili/FFmpeg.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
tools/pull-repo-ref.sh: line 11: cd: ios/ffmpeg-x86_64: No such file or directory
./init-ios.sh: line 64: cd: ios/ffmpeg-x86_64: No such file or directory
Cloning into 'ios/ffmpeg-i386'...
fatal: unable to access 'https://github.com/Bilibili/FFmpeg.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
tools/pull-repo-ref.sh: line 11: cd: ios/ffmpeg-i386: No such file or directory
./init-ios.sh: line 64: cd: ios/ffmpeg-i386: No such file or directory

这个问题是无法链接Bilibili服务器,搞了大半天,最后还是用手机热点才下载成功!建议切换网络多试几次

error2

AS  libavcodec/arm/aacpsdsp_neon.o
CC  libavcodec/arm/blockdsp_init_arm.o
./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....
clang: warning: optimization flag '-fomit-frame-pointer' is not supported for target 'armv7' [-Wignored-optimization-argument]

最新的 Xcode 已经弱化了对 32 位的支持, 解决方法:
compile-ffmpeg.sh 中删除 armv7 ,
修改前后对如下

修改1.png 修改2.png 修改3.png

修改之后,再重新执行出现错误的命令: ./compile-ffmpeg.sh all

error 3

The linked library 'libavcodec.a' is missing one or more architectures required by this target: armv7.

xcode12之后 编译真机的时候会出现该错误
解决思路是在Target👉 Build Settings 👉Excluded Architectures中添加以下代码,添加之后重新编译一次

EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64=arm64 arm64e armv7 armv7s armv6 armv8 EXCLUDED_ARCHS=$(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT))

error4
执行合并framework时可能会报错

Release-iphoneos/IJKMediaFramework.framework/IJKMediaFramework and Release-iphonesimulator/IJKMediaFramework.framework/IJKMediaFramework have the same architectures (arm64) and can't be in the same fat output file

解决方案
设置 Build Setting 👉 Excluded Architectures 👉Debug 👉添加上 arm64
设置 Build Setting 👉 Excluded Architectures 👉Release 👉添加上 arm64
出现的原因是XCode12 编译的模拟器库新增支持架构arm64。将模拟器的arm64给排除出去即可。

相关文章

网友评论

      本文标题:ijkplayer集成

      本文链接:https://www.haomeiwen.com/subject/edtuxrtx.html