ffmpeg编译iOS静态库教程

原文地址,直接进入正题了

本文大部分内容参考于此篇文章:How to Prepare Your Mac for iOS Development with FFmpeg Libraries , 然后针对最新情况做了一些修改。

1. 首先,准备编译环境

1. 安装Xcode和Command Line Tools
2. 下载和安装 gas-preprocessor
3. 安装 pkg-config

关于gas-preprocessor,安装方式是直接copy文件 gas-preprocessor.pl 到 /usr/bin ,记得修改权限可执行.

原文给出的下载地址是 gas-preprocessor , 不过这里的版本比较老 , 因为在编译ffmpeg的时候,gas-preprocessor版本必须和ffmpeg配合,所以如果你下载的ffmpeg源码是最新的,那么建议去 libav网站 下载最新的 gas-preprocessor.

如果之后在编译时候遇到类似这样的错误

unknown register alias 'TCOS_D0_HEAD'

那么可以尝试更换 gas-preprocessor版本来解决.

然后 pkg-config, 可以直接通过MacPorts来安装

sudo port install pkgconfig

2. 下载ffmpeg的源码

git clone git://source.ffmpeg.org/ffmpeg.git

3. 编译armv7的支持

configure参数如下

1
./configure --prefix=armv7 --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --enable-avresample --enable-cross-compile --sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk" --target-os=darwin --cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" --extra-cflags="-arch armv7 -mfpu=neon -miphoneos-version-min=5.1" --extra-ldflags="-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -miphoneos-version-min=5.1" --arch=arm --cpu=cortex-a9 --enable-pic

编译和安装到armv7目录下

1
make clean && make && make install

4. 编译armv7s的支持

configure参数如下

1
./configure --prefix=armv7s --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --enable-avresample --enable-cross-compile --sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk" --target-os=darwin --cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" --extra-cflags="-arch armv7s -mfpu=neon -miphoneos-version-min=5.1" --extra-ldflags="-arch armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -miphoneos-version-min=5.1" --arch=arm --cpu=cortex-a9 --enable-pic

编译和安装到armv7s目录下

1
make clean && make && make install

5. 编译i386的支持

configure参数如下

1
./configure --prefix=i386 --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --enable-avresample --enable-cross-compile --sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk" --target-os=darwin --cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc" --extra-cflags="-arch i386" --extra-ldflags="-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk" --arch=i386 --cpu=i386 --enable-pic --disable-asm

编译和安装到i386目录下

1
make clean && make && make install

如果一切顺利,那么ffmpeg目录下会分别生成 armv7、armv7s、i386几个目录,里面lib文件下就是我们需要的静态库了.

6. 最后,我们合并armv7、armv7s、i386库在一起.

1.建立universal/lib/目录.

2.新建bash脚本,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
#! /bin/sh

cd armv7/lib

for file in *.a
do
cd ../..
xcrun -sdk iphoneos lipo -output universal/lib/$file  -create -arch armv7 armv7/lib/$file -arch armv7s armv7s/lib/$file -arch i386 i386/lib/$file
echo "Universal $file created."
cd -
done
cd ../..

3.执行这个脚本,稍等完成后在universal/lib/下就是我们需要的静态库了。

以上这么简单的步骤就是编译ffmpeg为iOS静态库的方法,其他各种库编译方式也都大同小异.是不是很简单呢?

然后关于configure的参数,大家可以参考ffmepg官网解释

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在Windows环境下使用MSYS2编译FFmpeg静态库的步骤: 1. 安装MSYS2 首先需要下载并安装MSYS2,可以在官网上下载安装包:https://www.msys2.org/ 2. 安装编译工具和依赖项 打开MSYS2的终端,执行以下命令安装编译工具和依赖项: ``` pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-nasm git perl python3 ``` 3. 下载FFmpeg源码 从FFmpeg官网(https://ffmpeg.org/download.html)下载最新的源码包,解压到某个目录下。 4. 配置编译选项 在MSYS2的终端中进入FFmpeg源码目录,执行以下命令配置编译选项: ``` ./configure --disable-shared --enable-static --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-network --disable-iconv --disable-bzlib --disable-zlib --disable-lzma --disable-sdl2 --disable-xlib --disable-libxcb --disable-libxcb-shm --disable-libxcb-xfixes --disable-libxcb-shape --disable-lzma --disable-iconv --disable-libass --disable-libbluray --disable-libcaca --disable-libfontconfig --disable-libfreetype --disable-libfribidi --disable-libgme --disable-libgsm --disable-libilbc --disable-libkvazaar --disable-libmodplug --disable-libmp3lame --disable-libopencore-amrnb --disable-libopencore-amrwb --disable-libopenh264 --disable-libopenjpeg --disable-libopus --disable-libpulse --disable-librsvg --disable-librtmp --disable-libshine --disable-libsmbclient --disable-libsnappy --disable-libsoxr --disable-libspeex --disable-libssh --disable-libtesseract --disable-libtheora --disable-libtwolame --disable-libv4l2 --disable-libvorbis --disable-libvpx --disable-libwebp --disable-libx264 --disable-libx265 --disable-libxvid --disable-lzma --disable-zlib --disable-opencl --disable-opengl --disable-openssl --disable-libxml2 --arch=x86_64 --target-os=mingw32 --cross-prefix=x86_64-w64-mingw32- --pkg-config=pkg-config ``` 其中,--disable-shared和--enable-static表示编译静态库。 5. 编译并安装 执行以下命令编译并安装静态库: ``` make -j4 && make install ``` 其中,-j4表示使用4个线程编译,可以根据自己的CPU核心数进行调整。 6. 查找静态库 编译完成后,在MSYS2的终端中执行以下命令查找静态库: ``` find / -name '*.a' | grep ffmpeg ``` 可以看到类似如下的输出: ``` /usr/local/lib/libavcodec.a /usr/local/lib/libavdevice.a /usr/local/lib/libavfilter.a /usr/local/lib/libavformat.a /usr/local/lib/libavutil.a /usr/local/lib/libpostproc.a /usr/local/lib/libswresample.a /usr/local/lib/libswscale.a ``` 这些就是编译出来的FFmpeg静态库。 7. 使用静态库 在使用时,只需要将需要的静态库链接到自己的程序中即可。以使用libavformat静态库为例,在编译时需要加上-lavformat参数: ``` g++ -o myapp myapp.cpp -lavformat ``` 注意,编译时还需要加上其他依赖库的链接参数,具体可以参考FFmpeg官方文档:https://ffmpeg.org/documentation.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值