ijkplayer集成

一、環(huán)境準備

Mac系統(tǒng)版本: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 執(zhí)行成功
./compile-ffmpeg.sh all 

編譯過程中可能會出現(xiàn) error2

./compile-ffmpeg.sh a執(zhí)行成功

四、打包framework

  1. 打開ios/IJKMediaPlayer并運行
  2. 調(diào)整target


  3. 調(diào)整運行模式


  4. 分別編譯模擬器和真機
    編譯成功之后command + ,前往xcode設(shè)置頁 ?? Lications ?? Derived Data ?? IJKMediaPlayer-xxx ?? Build ?? Products

cdProducts文件夾下合并真機和模擬器的framework
執(zhí)行命令: lipo -create 真機framework路徑 模擬器framework路徑 -output 合并的文件路徑

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

執(zhí)行成功后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服務(wù)器,搞了大半天,最后還是用手機熱點才下載成功!建議切換網(wǎng)絡(luò)多試幾次

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 已經(jīng)弱化了對 32 位的支持, 解決方法:
compile-ffmpeg.sh 中刪除 armv7 ,
修改前后對如下

修改1.png

修改2.png
修改3.png

修改之后,再重新執(zhí)行出現(xiàn)錯誤的命令: ./compile-ffmpeg.sh all

error 3

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

xcode12之后 編譯真機的時候會出現(xiàn)該錯誤
解決思路是在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
執(zhí)行合并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

解決方案
設(shè)置 Build Setting ?? Excluded Architectures ??Debug ??添加上 arm64
設(shè)置 Build Setting ?? Excluded Architectures ??Release ??添加上 arm64
出現(xiàn)的原因是XCode12 編譯的模擬器庫新增支持架構(gòu)arm64。將模擬器的arm64給排除出去即可。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容