环境说明:
- macOS: 14.3.1 (23D60)
- Xcode: Version 15.4 (15F31d)
资源下载:
1.FFMpeg源码包下载地址:
网站 https://ffmpeg.org//download.html
macOS : https://evermeet.cx/ffmpeg/
1.下载 编译脚本
https://github.com/kewlbear/FFmpeg-iOS-build-script
也可以通过命令行
git clone https://github.com/kewlbear/FFmpeg-iOS-build-script.git
1.修改编译脚本
- FF_VERSION 修改为你当前下载的版本
- ARCHS 去除其中的 i386、armv7,i386是32位处理器的模拟器,armv7是32位的真机,都是较老的架构,编译时容易出现一些问题
- 如果你的FFMpeg版本是5.0以上,则需要将 DEPLOYMENT_TARGET 改为 13.0
- 在 CONFIGURE_FLAGS 中添加 --disable-audiotoolbox
- 如果不需要支持裁剪
则需要在CONFIGURE_FLAGS中 新增
# 禁止 ffplay、ffprobe、ffserver
--disable-ffplay --disable-ffprobe --disable-ffserve
环境安装:
1.安装brew工具
它是 macOS 最常用的软件/包管理工具
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
可参考 https://blog.csdn.net/lovechris00/article/details/121613647
2.安装 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/
3.安装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 -j 4 && sudo make install
4.其它依赖
brew install nasm yasm
编译:
1.执行 build-ffmpeg.sh 脚本
./build-ffmpeg.sh arm64 x86_64
2.结果
当前目前下会多出:FFmpeg-iOS, scratch, thin 这三个文件夹
集成:
1.将FFmpeg-iOS中的文件拖到项目中
2.修改 Search Paths
- Header Search Paths : $(SRCROOT)/ffdemo/FFmpeg-Apple/include
- Library Search Paths : $(SRCROOT)/ffdemo/FFmpeg-Apple/include
3.在 Xcode 中进行编译,应该会出现 Undefined symbols 的错误
则需要导入以下系统库:
- libz.tbd
- libbz2.tbd
- libiconv.tbd
- AVFoundation.framework
- CoreMedia.framework
- VideoToolBox.framework
- AudioToolBox.framework
注意:
若使用OpenGL绘制视频帧,还需导入OpenGLES.framework、 QuartzCore.framework。