iOS 开发 ijkplayer-ios 编译 支持https——2019-12-06

0. 编译环境

  • Mac OS X 10.15.1
  • Xcode 11.2.1 (11B53)

1. 安装 homebrew, git, yasm工具

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install git
brew install yasm

2. 从github上下载ijkplayer源码

# 进入到自己保存ijkplayer源代码位置路径
cd /Users/system/Workspace/Github

# 下载ijkplayer源代码
git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-ios

# 进入源码目录
cd ijkplayer-ios

# 切换分支(目前最新版本为k0.8.8,可以在ijkplayer-ios根目录下找到NEWS.md文件可以查看最新版本号)
git checkout -B latest k0.8.8

3. 配置编解码器格式

默认为最少支持, 如果足够你使用, 可跳过:

  • module-default.sh 更多的编解码器/格式
  • module-lite-hevc.sh 较少的编解码器/格式(包括hevc)
  • module-lite.sh 较少的编解码器/格式(默认情况)
# 进入 config目录
cd config

# 删除当前的 module.sh 文件
rm module.sh

# 可根据需要替换为`module-default.sh`, `module-lite-hevc.sh`, `module-lite.sh`
# 创建软链接 module.sh 指向 module-lite-hevc.sh
ln -s module-lite.sh module.sh

cd ..
cd ios
# 清空历史编译记录(如果有编译过)
sh compile-ffmpeg.sh clean

4. 获取 ffmpeg 并初始化

此过程需要从网上拉取ffmpeg,需要花些时间

cd ..
./init-ios.sh

5. 获取 openssl 并初始化(增加HTTPS支持)

编译完openssl后会生成支持 https 的静态文件 libcrypto.a 和 libssl.a,如不需要支持HTTPS可跳过i此步骤:

./init-ios-openssl.sh

cd ios

# 在模块文件中添加一行配置 以启用 openssl 组件
# 模块文件:
# module-default.sh 更多的编解码器/格式
# module-lite-hevc.sh 较少的编解码器/格式(包括hevc)
# module-lite.sh 较少的编解码器/格式(默认情况)
echo 'export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-openssl"' >> ../config/module.sh

./compile-ffmpeg.sh clean

6. 编译

# 如果下一步提示错误`xcrun: error: SDK "iphoneos" cannot be located`, 请执行`sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/`, 再重新执行下一步

# 编译openssl, 如不需要https可跳过
./compile-openssl.sh all

# 编译ffmpeg
./compile-ffmpeg.sh all

如果编译ffmpeg提示如下错误:

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

最新的 Xcode 环境中iOS SDK最低支持从iOS 8.0开始了,弱化了对 32 位iOS系统的支持,解决方法:
compile-ffmpeg.sh 中删除 armv7 , 修改如:
FF_ALL_ARCHS_IOS8_SDK="arm64 i386 x86_64"
再重新执行出现错误的命令: ./compile-ffmpeg.sh all

7. 打开 IJKMediaDemo 项目

open IJKMediaDemo/IJKMediaDemo.xcodeproj

也可以手动用 Xcode 打开 ios 目录下的 IJKMediaDemo 项目.

command + B Build一下发现报出以下错误:

Ld /Users/system/Library/Developer/Xcode/DerivedData/IJKMediaDemo-bnncwcpyzeijjachazvkcxsjbdll/Build/Products/Debug-iphoneos/IJKMediaDemo.app/IJKMediaDemo normal arm64 (in target 'IJKMediaDemo' from project 'IJKMediaDemo')
    cd /Users/system/Workspace/Github/ijkplayer-ios/ios/IJKMediaDemo
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target arm64-apple-ios8.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk -L/Users/system/Library/Developer/Xcode/DerivedData/IJKMediaDemo-bnncwcpyzeijjachazvkcxsjbdll/Build/Products/Debug-iphoneos -F/Users/system/Library/Developer/Xcode/DerivedData/IJKMediaDemo-bnncwcpyzeijjachazvkcxsjbdll/Build/Products/Debug-iphoneos -filelist /Users/system/Library/Developer/Xcode/DerivedData/IJKMediaDemo-bnncwcpyzeijjachazvkcxsjbdll/Build/Intermediates.noindex/IJKMediaDemo.build/Debug-iphoneos/IJKMediaDemo.build/Objects-normal/arm64/IJKMediaDemo.LinkFileList -dead_strip -Xlinker -object_path_lto -Xlinker /Users/system/Library/Developer/Xcode/DerivedData/IJKMediaDemo-bnncwcpyzeijjachazvkcxsjbdll/Build/Intermediates.noindex/IJKMediaDemo.build/Debug-iphoneos/IJKMediaDemo.build/Objects-normal/arm64/IJKMediaDemo_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -fembed-bitcode-marker -fobjc-arc -fobjc-link-runtime -lstdc++ -lbz2 -lz -framework AudioToolbox -framework AVFoundation -framework CoreGraphics -framework CoreMedia -framework CoreVideo /Users/system/Library/Developer/Xcode/DerivedData/IJKMediaDemo-bnncwcpyzeijjachazvkcxsjbdll/Build/Products/Debug-iphoneos/IJKMediaFramework.framework/IJKMediaFramework -framework MediaPlayer -framework MobileCoreServices -framework OpenGLES -framework QuartzCore -framework UIKit -framework VideoToolbox -Xlinker -dependency_info -Xlinker /Users/system/Library/Developer/Xcode/DerivedData/IJKMediaDemo-bnncwcpyzeijjachazvkcxsjbdll/Build/Intermediates.noindex/IJKMediaDemo.build/Debug-iphoneos/IJKMediaDemo.build/Objects-normal/arm64/IJKMediaDemo_dependency_info.dat -o /Users/system/Library/Developer/Xcode/DerivedData/IJKMediaDemo-bnncwcpyzeijjachazvkcxsjbdll/Build/Products/Debug-iphoneos/IJKMediaDemo.app/IJKMediaDemo

Undefined symbols for architecture arm64:
  "_ERR_error_string", referenced from:
      _OUTLINED_FUNCTION_2 in IJKMediaFramework(tls_openssl.o)
  "_SSL_shutdown", referenced from:
      _tls_close in IJKMediaFramework(tls_openssl.o)
  "_SSL_write", referenced from:
      _tls_write in IJKMediaFramework(tls_openssl.o)
  "_CRYPTO_get_locking_callback", referenced from:
      _ff_openssl_init in IJKMediaFramework(tls_openssl.o)
      _ff_openssl_deinit in IJKMediaFramework(tls_openssl.o)
  "_SSL_read", referenced from:
      _tls_read in IJKMediaFramework(tls_openssl.o)
  "_SSL_CTX_free", referenced from:
      _tls_close in IJKMediaFramework(tls_openssl.o)
  "_SSL_CTX_use_certificate_chain_file", referenced from:
      _tls_open in IJKMediaFramework(tls_openssl.o)
  "_SSL_CTX_ctrl", referenced from:
      _tls_open in IJKMediaFramework(tls_openssl.o)
  "_SSL_CTX_use_PrivateKey_file", referenced from:
      _tls_open in IJKMediaFramework(tls_openssl.o)
  "_BIO_clear_flags", referenced from:
      _url_bio_ctrl in IJKMediaFramework(tls_openssl.o)
      _OUTLINED_FUNCTION_5 in IJKMediaFramework(tls_openssl.o)
  "_SSLv23_server_method", referenced from:
      _tls_open in IJKMediaFramework(tls_openssl.o)
  "_SSL_CTX_set_verify", referenced from:
      _tls_open in IJKMediaFramework(tls_openssl.o)
  "_SSL_new", referenced from:
      _tls_open in IJKMediaFramework(tls_openssl.o)
  "_SSL_accept", referenced from:
      _tls_open in IJKMediaFramework(tls_openssl.o)
  "_SSL_set_bio", referenced from:
      _tls_open in IJKMediaFramework(tls_openssl.o)
  "_SSLv23_client_method", referenced from:
      _tls_open in IJKMediaFramework(tls_openssl.o)
  "_SSL_library_init", referenced from:
      _ff_openssl_init in IJKMediaFramework(tls_openssl.o)
  "_CRYPTO_num_locks", referenced from:
      _ff_openssl_init in IJKMediaFramework(tls_openssl.o)
      _ff_openssl_deinit in IJKMediaFramework(tls_openssl.o)
  "_ERR_get_error", referenced from:
      _tls_open in IJKMediaFramework(tls_openssl.o)
      _print_tls_error in IJKMediaFramework(tls_openssl.o)
  "_SSL_CTX_load_verify_locations", referenced from:
      _tls_open in IJKMediaFramework(tls_openssl.o)
  "_BIO_new", referenced from:
      _tls_open in IJKMediaFramework(tls_openssl.o)
  "_SSL_connect", referenced from:
      _tls_open in IJKMediaFramework(tls_openssl.o)
  "_SSL_free", referenced from:
      _tls_close in IJKMediaFramework(tls_openssl.o)
  "_SSL_CTX_new", referenced from:
      _tls_open in IJKMediaFramework(tls_openssl.o)
  "_SSL_load_error_strings", referenced from:
      _ff_openssl_init in IJKMediaFramework(tls_openssl.o)
  "_SSL_ctrl", referenced from:
      _tls_open in IJKMediaFramework(tls_openssl.o)
  "_CRYPTO_set_locking_callback", referenced from:
      _ff_openssl_init in IJKMediaFramework(tls_openssl.o)
      _ff_openssl_deinit in IJKMediaFramework(tls_openssl.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


Showing Recent Messages:
Undefined symbol: _ERR_error_string
Undefined symbol: _SSL_shutdown
Undefined symbol: _SSL_write
Undefined symbol: _CRYPTO_get_locking_callback
Undefined symbol: _SSL_read
Undefined symbol: _SSL_CTX_free
Undefined symbol: _SSL_CTX_use_certificate_chain_file
...

image.png

出错原因是因为既然添加了https的支持,需要把依赖的openssl库给关联进来。解决办法:
IJKMediaDemo->IJKMediaPlayer.xcodeproj->Classes->IJKFFMoviePlayerController->ffmpeg->lib
按照上面的可以看到该文件夹,然后鼠标右击delete -> Remove References.
接下来,重新把ffmpeg编译的库静态.a文件和include中的头文件拖进来,找到ijkplayer-ios存放的目录,我这里是:

/Users/system/Workspace/Github/ijkplayer-ios

然后进入到ijkplayer-ios下的ios/build/universal,可以看到includelib两个文件夹,然后把他们拖到IJKMediaDemo刚才的位置中:
IJKMediaDemo->IJKMediaPlayer.xcodeproj->Classes->IJKFFMoviePlayerController->ffmpeg

1.png

2.png
Destination: Copy items if needed
Added folders: Create groups
Add to targets: IJKMediaFramework
image.png

8. 测试地址

http://static.tripbe.com/videofiles/20121214/9533522808.f4v.mp4
http://img.ksbbs.com/asset/Mon_1703/05cacb4e02f9d9e.mp4

https://media.w3.org/2010/05/sintel/trailer.mp4
https://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_20mb.mp4

完结

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,547评论 6 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,399评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,428评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,599评论 1 274
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,612评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,577评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,941评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,603评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,852评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,605评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,693评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,375评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,955评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,936评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,172评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 43,970评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,414评论 2 342

推荐阅读更多精彩内容