织梦CMS - 轻松建站从此开始!

罗索

iphone ffmpeg 解码库得移植

落鹤生 发布于 2013-01-28 12:37 点击:次 
下面得这篇文章是本人见过得最nb得文章.直接下载源码,按照提示,没有半天问题,直接编译过了.
TAG:

下面得这篇文章是本人见过得最nb得文章.
直接下载源码,按照提示,没有半天问题,直接编译过了.

ffmpeg iphone 编译为设备库文件

1.下载ffmpeg:打开终端,输入:git clone git://git.videolan.org/ffmpeg.git

2.下载gas-preprocessor.pl 下载地址为https://github.com/yuvi/gas-preprocessor, 该文件作用就是在mac机上生成指定的汇编文件

3. 拷贝gas-preprocessor到/usr/local/bin 目录下面 cp gas-preprocessor.pl /usr/local/bin

4.在终端下执行如下命令:

./configure --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffserver --as='gas-preprocessor.pl /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' --enable-cross-compile --arch=arm --target-os=darwin --cc='/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv7' --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk --cpu=cortex-a8 --enable-pic

5.执行make命令

6.copy需要的.a 文件,目前iphone编解码用到下列五个库文件:

libavcodec.a
libavdevice.a
libavformat.a
libavutil.a
libswscale.a

7.xcode使用的时候设置header search path的路径为ffmpeg,勾选前面的复选框,递归查找header文件即可。

上述配置适合编译为指定的设备文件。

 

这篇文章可以参考下:


https://github.com/gabriel/ffmpe ... /master/build-armv6

OK ,接着昨天得说,按照上面得做法,基本可以编译出大家所需要得库。如果你没编译成功,那么大家可以直接用一个开源项目得.

 

ffmpeg4iphone(里面包含ffmpeg和opengles渲染方面得代码)

 

按照我上面得步骤,其实编译出来得文件超级大.

 

正确得做法是./configure --help

 

去掉那些不会用到得情况.


接下来是使用方面得问题:

 

-(IBAction) decode

 

{

 

        NSLog(@"decode h264");

 

       

 

       

 

        AVCodec* m_pCodec;

 

        AVCodecContext* m_pCodecContext;

 

        AVFrame* m_pFrame;

 

       

 

//        avcodec_init();

 

//        avcodec_register_all();

 

       

 

       

 

        avcodec_register(&ff_h264_decoder);

 

       

 

        m_pCodec = avcodec_find_decoder(CODEC_ID_H264);

 

        if (m_pCodec==NULL) {

 

                NSLog(@"can not find decoder");

 

                return;

 

        }

 

       

 

       

 

        m_pCodecContext = avcodec_alloc_context3(m_pCodec);

 

        if (m_pCodecContext==NULL) {

 

                NSLog(@"can not find codecContext");

 

                return;

 

        }

 

       

 

       

 

        m_pFrame = avcodec_alloc_frame();

 

        if (m_pFrame==NULL) {

 

                NSLog(@"m_pFrame is NULL");

 

                return;

 

        }

 

       

 

       

 

        m_pCodecContext->flags |= CODEC_FLAG_EMU_EDGE | CODEC_FLAG_LOW_DELAY;

 

        m_pCodecContext->debug |= FF_DEBUG_MMCO;

 

        if (avcodec_open2(m_pCodecContext, m_pCodec,NULL)) {

 

                printf("avcode_open fail\n");

 

                return;

 

        }

 

       

 

        NSLog(@"step 1 ok");

 

       

 

        AVPacket m_packet;

 

        av_init_packet(&m_packet);

 

       

 

        //h264数据

 

//        m_packet.data =

 

       

 

        //h264长度

 

//  m_packet.size=

 

       

 

        NSString* resource_path = [[NSBundle mainBundle] resourcePath];

 

        NSString* resource_h264 = [resource_path stringByAppendingString:@"/iframe.264"];

 

        NSData* data_h264 = [NSData dataWithContentsOfFile:resource_h264];

 

       

 

        const char* p_h264 = [data_h264 bytes];

 

        int length = [data_h264 length];

 

       

 

        m_packet.data = p_h264;

 

        m_packet.size = length;

 

       

 

        int got_picture_ptr=0;

 

       

 

       

 

        int ret = avcodec_decode_video2(m_pCodecContext,m_pFrame,&got_picture_ptr,&m_packet);

 

        NSLog(@"ret:%d",ret);

 

       

 

        int width = m_pFrame->width;

 

        int height = m_pFrame->height;

 

        NSLog(@"width:%d -height:%d",width,height);

 

经过本人亲测,代码无误.

 

贡献下我自己写得./configure 文件:

 

./configure --cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk --prefix="dist" --enable-cross-compile --target-os=darwin --arch=arm --cpu=arm1176jzf-s --extra-cflags='-arch armv6' --extra-ldflags='-arch armv6' --disable-doc --disable-ffplay --disable-ffprobe --disable-ffserver --disable-swresample --disable-swscale --disable-postproc --disable-avfilter --disable-avresample --disable-dct --disable-mdct --disable-rdft --disable-fft --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --disable-ffmpeg --disable-everything --enable-decoder=h264

 

生成得库文件总大小再4M左右.

 

最近测试发现在ios5.0的机器上有问题:

 

1../configure 提示 gas-preprocessor.pl找不到

 

cp gas-preprocessor.pl /usr/local/bin

 

如果上面的操作不行,那么就这样: cp gas-preprocessor.pl /usr/bin

 

2。编译的时候会有一些inline asm编译不过,这个好解决:

 

在生成的.config.h中

 

#define HAVE_INLINE_ASM 1

 

把该选项更改为:

 

#define HAVA_INLINE_ASM 0

 

我个人写的./configure

 

./configure --cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc  --as='gas-preprocessor.pl /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk --extra-ldflags=-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/system --target-os=darwin --arch=arm  --extra-cflags='-W -arch armv7 -mfpu=neon' --extra-ldflags='-arch armv7 -mfpu=neon' --enable-cross-compile  --enable-pic --disable-doc --disable-ffplay --disable-ffprobe --disable-ffserver --disable-swresample --disable-swscale --disable-postproc --disable-avfilter --disable-dct --disable-mdct --disable-fft --disable-dxva2 --disable-vaapi --disable-vda --disable-ffmpeg --disable-everything --enable-decoder=h264 --disable-avdevice --disable-avformat

(秩名)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201301/16492.html]
本文出处:shouyanwang 作者:秩名 原文
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容