iphone/ipad 项目上的 FFMPEG 集成 [英] FFMPEG integration on iphone/ ipad project

查看:38
本文介绍了iphone/ipad 项目上的 FFMPEG 集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何将 FFMPEG 集成到我的 iphone/ipad 项目中.我正在使用 Xcode 4.我搜索了很多,但没有找到任何有用的链接.请告诉我将 FFMpeg 集成到我的项目中的分步过程.

Can any One Tell me how do i integrate FFMPEG in my iphone/ ipad project.i m using Xcode 4. i searched a lot but did not find any useful Link .please tell me step by step procedure to integrate FFMpeg in my project.

谢谢,

推荐答案

先决条件

要安装的 MacPorts:打开终端并输入

MacPorts to install:open terminal and type

sudo 端口安装 pkgconfig

sudo port install pkgconfig

启动终端并下载 FFmpeg 源

目录的位置取决于您的个人喜好,我选择将其保存在我的主文件夹下的 ffmpeg 文件夹中,以便以后访问.

The location of the directory is up to your personal preference and I chose to save it in a ffmpeg folder under my Home folder for easy access later on.

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

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

在我们进一步研究之前,我们需要提前考虑并意识到我们可能会在 Mac 本身上进行一些模拟,同时在 iPhone 上进行实际测试.我们需要做的是,我们需要为 3 种架构构建库:armv7(iPhone 3Gs 或更高版本)、armv7s(iPhone 5)和 i386(iPhone 模拟器).

Before we go further, we need to think ahead and realize that we are likely to do some simulation on Mac itself along with actual testing on iPhone. What we need to do is that we need to build libraries for 3 architectures: armv7 (iPhone 3Gs or later), armv7s (iPhone 5) and i386 (iPhone Simulator).

让我们在 ffmpeg 文件夹中创建一些文件夹来保存 3 个不同的构建,以便我们可以将它们整合到一个通用构建中.

Let’s create some folders inside ffmpeg folder to hold 3 different builds so that we can lipo those together into one universal build.

cd ffmpegmkdir armv7mkdir armv7smkdir i386mkdir -p 通用/库

cd ffmpeg mkdir armv7 mkdir armv7s mkdir i386 mkdir -p universal/lib

安装气体预处理器

  1. 点击 ZIP 图标下载气体预处理器.
  2. 将 gas-preprocessor.pl 复制到/usr/bin 目录.
  3. 通过将权限设置为 Read & 来更改 gas-preprocessor.pl 的权限为所有人写作.

为 armv7 构建配置 FFmpeg

在配置之前,您可以通过进入ffmpeg文件夹并输入以下内容来参考详细选项:

Before configuring, You may refer to the detailed options by going in to the ffmpeg folder and type:

./configure --help

./configure --help

供您参考的选项列表:FFmpeg 配置选项.组件选项"取决于你想用 FFmpeg 做什么.

list of options for your reference: FFmpeg Configure Options. The "Components options" will be up to you depending on what you want to do with FFmpeg.

现在运行以下配置选项:

Now run the following configure options:

./configure --prefix=armv7 --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --enable-avresample --启用交叉编译--sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk"--target-os=达尔文--cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc"--extra-cflags="-arch armv7 -mfpu=neon -miphoneos-version-min=6.0" --extra-ldflags="-arch armv7 -isysroot/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk-miphoneos-version-min=6.0" --arch=手臂 --cpu=cortex-a9 --enable-pic

./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.0.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=6.0" --extra-ldflags="-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk -miphoneos-version-min=6.0" --arch=arm --cpu=cortex-a9 --enable-pic

您可能会收到如下警告:

You may get a warning such as:

警告:编译器不指示浮点 ABI,猜测是软的.

WARNING: Compiler does not indicate floating-point ABI, guessing soft.

不用担心.您应该可以继续下一步.

No worries. You should be fine to continue to next steps.

为 armv7 构建 FFmpeg

Build FFmpeg for armv7

运行构建命令:

清洁&&制作&&进行安装

make clean && make && make install

现在您应该能够看到文件填充在 ffmpeg/armv7 文件夹中.我们现在开始为 iPhone 5 的 armv7s 构建.

Now you should be able to see files are populated inside the ffmpeg/armv7 folder. We now move onto building for armv7s for iPhone 5.

为 armv7s 架构(iPhone 5)配置和安装 FFmpeg

./配置 --prefix=armv7s --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --enable-avresample --启用交叉编译--sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk"--target-os=达尔文--cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc"--extra-cflags="-arch armv7s -mfpu=neon -miphoneos-version-min=6.0" --extra-ldflags="-arch armv7s -isysroot/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk-miphoneos-version-min=6.0" --arch=手臂 --cpu=cortex-a9 --enable-pic

. /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.0.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=6.0" --extra-ldflags="-arch armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk -miphoneos-version-min=6.0" --arch=arm --cpu=cortex-a9 --enable-pic

然后构建:

清洁&&制作&&进行安装

make clean && make && make install

为 i386 构建配置 FFmpeg

./configure --prefix=i386 --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --enable-avresample --启用交叉编译--sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk"--target-os=达尔文--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.0.sdk"--arch=i386 --cpu=i386 --启用图片--disable-asm

./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.0.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.0.sdk" --arch=i386 --cpu=i386 --enable-pic --disable-asm

请注意最后一个 --disable-asm 标签.如果您忘记包含此标签,您可能会收到此错误:

Please note the last --disable-asm tag. If you forget to include this tag, you will likely to receive this error:

cc1:后端错误:注册期间寄存器用完分配!制作:*** [libavcodec/h264_cabac.o] 错误 1

cc1: error in backend: Ran out of registers during register allocation! make: *** [libavcodec/h264_cabac.o] Error 1

为 i386 构建 FFmpeg

清洁&&制作&&进行安装

make clean && make && make install

创建通用库

lipo 命令(假设您仍在 ffmpeg 文件夹下):(请注意,Mountain Lion 提供的 lipo 对 armv7s 一无所知.所以我们需要使用 xcrun 找到 SDK 提供的 lipo.)

The lipo commands (assuming you are still under the ffmpeg folder): (Please note that Mountain Lion-supplied lipo knows nothing about armv7s as of yet. So we need to use xcrun to find the lipo supplied with the SDK.)

cd armv7/lib for file in *.a do cd ../.. xcrun -sdk iphoneos lipo-输出通用/lib/$file -create -arch armv7 armv7/lib/$file -arch armv7s armv7s/lib/$file -arch i386 i386/lib/$file echo "已创建通用 $file."cd - 完成 cd ../..

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 ../..

查看universal/lib,你会发现所有的FAT libs都是新鲜出炉的.我们现在将注意力转向将这些静态库链接到 Xcode 项目.

Look under universal/lib, you will find all FAT libs freshly baked there. We now turn our attention to linking these static libraries to the Xcode project.

如果您收到这样的错误错误:在/Developer 中找不到开发者目录?然后输入

if you are getting error like this Error: No developer directory found at /Developer"? then type

sudo xcode-select -switch/Applications/Xcode.app/Contents/Developer

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

在 Xcode 中链接静态库

首先,我们拉入 .a 文件.

Firstly, we pull in the .a files.

使用 Xcode 创建一个新的空应用程序.分配产品名称和公司标识符.然后单击下一步并保存项目.在 ffmpeg/universal/lib 下找到我们创建的通用库(.a 文件).将 .a 文件拖到 Project Navigator 窗格中的 Frameworks 文件夹中.勾选将项目复制到目标组的文件夹(如果需要)".然后点击完成.

Create a new Empty Application using Xcode. Assign a Product Name and Company Identifier. Then click Next and save the project. Locate the universal libs that we created (the .a files) under ffmpeg/universal/lib. Drag the .a files into the Frameworks folder in the Project Navigator pane. Tick "Copy items into destination group’s folder (if needed)". And click Finish.

现在我们处理包含文件.

Now we take care of the include files.

ffmpeg/armv7/include 下找到包含文件.将该文件夹的内容拖放到 Project Navigator 窗格中的 Project Name 文件夹中.再次勾选将项目复制到目标组的文件夹(如果需要)".然后点击完成.

Locate the include files under ffmpeg/armv7/include. Drag and drop the content of that folder onto the Project Name folder in the Project Navigator pane. Again, tick "Copy items into destination group’s folder (if needed)". Then click Finish.

最后,我们需要为项目设置标题搜索路径.

单击项目导航器"窗格中的项目.在屏幕中间的标准编辑器中,单击构建设置.搜索标题搜索路径".添加您的项目路径并将其设置为递归.即 $(SRCROOT)单击构建阶段.在 Link Binary With Libraries 下,添加 libbz2.dyliblibz.dylib.

Click on the Project in the Project Navigator pane. In the Standard Editor in the middle of the screen, click on Build Settings. Search for "Header Search Paths". Add your project path and set it to Recursive. i.e. $(SRCROOT) Click on Build Phases. Under Link Binary With Libraries, add libbz2.dylib and libz.dylib.

测试和验证库的工作

我们不会在这里深入.只是为了验证库是否正常运行.转到您的 AppDelegate.m,并添加:

We are not going to be in-depth here. Just to verify that the library is functioning. Go to your AppDelegate.m, and add:

> #include "avformat.h"

并在 didFinishLaunchingWithOptions 函数中,添加:

And in the didFinishLaunchingWithOptions function, add:

av_register_all();

如果假设您收到此错误意味着

if suppose you are getting this errors means

架构 i386 的未定义符号:_iconv",引用自:libmailcore.a(charconv.o) 中的_mail_iconv_iconv_open",引用自:libmailcore.a(charconv.o) 中的_charconvlibmailcore.a(charconv.o) 中的_charconv_buffer_iconv_close",引用自:libmailcore.a(charconv.o) 中的_charconvlibmailcore.a(charconv.o) 中的_charconv_bufferld:找不到架构 i386 的符号collect2: ld 返回 1 个退出状态

然后添加libiconv.dylib框架

您现在可以开始在 iOS 上使用 FFmpeg 进行开发了.

you are now ready to dive in to develop using FFmpeg on iOS.

这篇关于iphone/ipad 项目上的 FFMPEG 集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆