iOS 开发之编译ffmpeg 及报错解析

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完美解决。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1.super:super和this不是类似的,this是对象的引用,super不是一个对象的引用,不能将supe...
    luckee阅读 3,856评论 0 0
  • It's Thursday. Jack cowered down and was still. The pony ...
    Mr_Oldman阅读 1,256评论 0 0
  • Major Opioid Maker to Pay for Overdose-Antidote Developme...
    Berry521阅读 421评论 0 0
  • 惊蛰日,水寒雾浓封锁浴场 五十米开外 看不见山光水影 水中,一层冰衣是一层皮 突听老哥喊:大姐独自游往远方 请亲们...
    东山岛高永川阅读 1,310评论 0 0
  • liDawei阅读 1,216评论 0 0

友情链接更多精彩内容