iOS 开发之编译ffmpeg 及报错解析
一、脚本编译
1. 编译Mac下可用 FFmpeg
编译Mac下可用 FFmpeg,主要是可以在mac中,使用 FFmpeg 进行操作视频等。
Homebrew介绍
简称brew,是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件。
Homebrew安装
打开终端执行
```
ruby -e "$(curl -fsSLhttps://raw.githubusercontent.com/Homebrew/install/master/install)”)"
```
Homebrew命令使用
搜索软件:brew search 软件名, 如brew search wget
安装软件:brew install 软件名, 如brew install wget
卸载软件:brew remove 软件名,如brew remove wget
通过Homebrew 安装 FFmpeg
终端执行:执行 brew install ffmpeg --with-libvpx --with-libvorbis --with-ffplay
在终端中执行一下命令,等待安装完成即可:
```
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
```
安装好Homebrew,然后终端执行 "brew install ffmpeg",等待完成即可。
执行结束,在终端中输入ffmpeg,验证是否安装成功。
2. 编译 iOS 下 FFmpeg
主要是用于iOS下可用的FFmpeg
手动编译FFmpeg网上有一些方法,但是稍显复杂而陈旧, 所以现在大部分都是使用FFmpeg-iOS-build-script.sh这个脚本,比较方便直接
FFmpeg-iOS-build-script 是一个外国人写的自动编译的脚本,脚本则会自动从github中把ffmpeg源码下到本地并开始编译出iOS可用的库,支持各种架构。
在进行编译之前,需要做一些准备工作安装必备文件:
2.1 安装 gas-preprocessor
后面运行 FFmpeg-iOS-build-script 这个自动编译脚本需要 gas-preprocessor .
安装步骤(依次执行下面命令):
```
sudo git clone https://github.com/bigsen/gas-preprocessor.git /usr/local/bin/gas
sudo cp /usr/local/bin/gas/gas-preprocessor.pl /usr/local/bin/gas-preprocessor.pl
sudo chmod 777 /usr/local/bin/gas-preprocessor.pl
sudo rm -rf /usr/local/bin/gas/
```
2.2 安装 yams
yasm是汇编编译器,因为ffmpeg中为了提高效率用到了汇编指令,所以编译时需要安装
安装步骤(依次执行下面命令):
```
curl http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz-o yasm-1.2.0.gz
tar-zxvf yasm-1.2.0.gz
cd yasm-1.2.0
./configure&&make-j4&&sudomakeinstall
```
2.3 配置 FFmpeg 编译脚本
下载编译脚本
```
git clone https://github.com/kewlbear/FFmpeg-iOS-build-script.git
```
2. 执行 build-ffmpeg.sh
cd 到 build-ffmpeg.所在的目录下,然后执行:
```
./build-ffmpeg.sh
```
这个时候如果你的Mac曾经安装过多个版本的Xcode ,执行./build-ffmpeg.sh 时可能会报错:
building arm64...
xcrun -sdk iphoneos clang is unable to create an executable file.
C compiler test failed.
If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.
3. 报错分析
这个报错说的是交叉编译时找不到 iphoneos sdk 的可执行文件,这是因为安装多版本xcode 后造成访问Xcode路径判断错误引起的。
4. 解决方法
在终端中执行:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/
执行时需要输入Mac 登录密码,输入密码enter即可。
说明: 这是设置Xcode 的默认访问路径
执行完后,再执行:
./build-ffmpeg.sh
这个时候不会再报刚才的错误了,OK完美解决。