问题前提:
新公司项目用到 ijkplayer 进行直播业务的播放,接手项目后有个业务需求对拉流延迟要求比较高,经过一系列 debug 后发现 iOS 端 ijkplayer 延迟略大于 Android 端,于是决定对 ijkplayer 的高延迟问题进行调优
前面的准备工作在这里不做赘述,在编译 ffmpeg 时(执行./compile-ffmpeg.sh all
)时会有报错,如下:
./libavutil/arm/asm.S:44:9: error: unknown directive
.arch armv7-a
^
./libavutil/arm/asm.S:57:9: error: unknown directive
.fpu neon
^
make: *** [libavcodec/arm/aacpsdsp_neon.o] Error 1
make: *** Waiting for unfinished jobs....
ijkplayer 的编译、打包 framework 和 https 支持这篇文章中讲述最新的 Xcode 生成二进制包所支持的指令集排除了armv7
,并提供了解决方案,大家可以参考,我尝试了一下确实可行。
鉴于我们项目目前支持的指令集包括armv7
,所以我尝试了其他方法解决这个错误,我尝试了旧版 Xcode 尝试无果(最新的 macOS 也不支持下载过老的 Xcode 版本)。最后找到如下的解决方案:
在/iOS/tools/do-compile-ffmpeg.sh
中
将
FFMPEG_CFG_FLAGS="$FFMPEG_CFG_FLAGS $FFMPEG_CFG_FLAGS_ARM"
修改为
FFMPEG_CFG_FLAGS="$FFMPEG_CFG_FLAGS --enable-pic --disable-asm"
然后重新执行
./compile-ffmpeg.sh all
这样我们再打开IJKMediaDemo
项目就可以运行起来了
其他问题
问题1:
运行IJKMediaDemo
报错如下:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_IJKFFOptions", referenced from:
objc-class-ref in IJKMoviePlayerViewController.o
"_OBJC_CLASS_$_IJKFFMoviePlayerController", referenced from:
objc-class-ref in IJKMoviePlayerViewController.o
"_IJKMPMoviePlayerLoadStateDidChangeNotification", referenced from:
-[IJKVideoViewController installMovieNotificationObservers] in IJKMoviePlayerViewController.o
-[IJKVideoViewController removeMovieNotificationObservers] in IJKMoviePlayerViewController.o
"_IJKMPMoviePlayerPlaybackDidFinishReasonUserInfoKey", referenced from:
-[IJKVideoViewController moviePlayBackDidFinish:] in IJKMoviePlayerViewController.o
"_IJKMPMoviePlayerPlaybackDidFinishNotification", referenced from:
-[IJKVideoViewController installMovieNotificationObservers] in IJKMoviePlayerViewController.o
-[IJKVideoViewController removeMovieNotificationObservers] in IJKMoviePlayerViewController.o
"_IJKMPMediaPlaybackIsPreparedToPlayDidChangeNotification", referenced from:
-[IJKVideoViewController installMovieNotificationObservers] in IJKMoviePlayerViewController.o
-[IJKVideoViewController removeMovieNotificationObservers] in IJKMoviePlayerViewController.o
"_IJKMPMoviePlayerPlaybackStateDidChangeNotification", referenced from:
-[IJKVideoViewController installMovieNotificationObservers] in IJKMoviePlayerViewController.o
-[IJKVideoViewController removeMovieNotificationObservers] in IJKMoviePlayerViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
解决办法:
Build Phases - Link Binary With Libraries - "+",添加IJKMediaFramework.framework
,再次运行就可以运行成功了(模拟器运行即可)
问题2:通过如下命令进行真机和模拟器framework合并时:
lipo -create Release-iphoneos/IJKMediaFramework.framework/IJKMediaFramework Release-iphonesimulator/IJKMediaFramework.framework/IJKMediaFramework -output IJKMediaFramework
输出如下错误:
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: 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
这是因为Xcode 12 之前
编译模拟器静态库支持i386
和x86_64
架构,Xcode 12 之后
也支持arm64
架构,而编译真机静态库支持arm64
和armv7
架构,所以导致合并时有冲突
解决办法:
用Xcode 11
编译静态库后进行合并
未完待续...