下面得这篇文章是本人见过得最nb得文章.
这篇文章可以参考下:
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 (秩名) |