一、環(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
- 克隆倉庫到本地
//克隆倉庫到指定位置并重命名為ijkplayer-ios
git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-ios
- 新增一個本地分支(可選項)
git checkout -B latest k0.8.8
- 下載
ffmpeg(常見錯誤見下面錯誤錦集)
./init-ios.sh
- 下載成功后進入
ios文件夾
cd ios
三、編譯 fffmpeg
./compile-ffmpeg.sh clean

./compile-ffmpeg.sh all
編譯過程中可能會出現(xiàn) error2

四、打包framework
- 打開
ios/IJKMediaPlayer并運行 -
調(diào)整target
-
調(diào)整運行模式
- 分別編譯模擬器和真機
編譯成功之后command + ,前往xcode設(shè)置頁 ?? Lications ?? Derived Data ?? IJKMediaPlayer-xxx ?? Build ?? Products
cd 到 Products文件夾下合并真機和模擬器的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 ,
修改前后對如下



修改之后,再重新執(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給排除出去即可。



