【问题标题】:iPhone - A problem with decoding H264 using ffmpegiPhone - 使用 ffmpeg 解码 H264 的问题
【发布时间】:2011-08-24 23:58:45
【问题描述】:

我正在使用 ffmpeg 从服务器解码 H264 流。

我从http://github.com/dropcam/dropcam_for_iphone引用了DecoderWrapper。

编译成功了,不知道怎么用。

这是有问题的功能。

- (id)initWithCodec:(enum VideoCodecType)codecType 
         colorSpace:(enum VideoColorSpace)colorSpace 
              width:(int)width 
             height:(int)height 
        privateData:(NSData*)privateData {
    if(self = [super init]) {

        codec = avcodec_find_decoder(CODEC_ID_H264);
        codecCtx = avcodec_alloc_context();

        // Note: for H.264 RTSP streams, the width and height are usually not specified (width and height are 0).  
        // These fields will become filled in once the first frame is decoded and the SPS is processed.
        codecCtx->width = width;
        codecCtx->height = height;

        codecCtx->extradata = av_malloc([privateData length]);
        codecCtx->extradata_size = [privateData length];
        [privateData getBytes:codecCtx->extradata length:codecCtx->extradata_size];
        codecCtx->pix_fmt = PIX_FMT_YUV420P;
#ifdef SHOW_DEBUG_MV
        codecCtx->debug_mv = 0xFF;
#endif

        srcFrame = avcodec_alloc_frame();
        dstFrame = avcodec_alloc_frame();

        int res = avcodec_open(codecCtx, codec);
        if (res < 0)
        {
            NSLog(@"Failed to initialize decoder");
        }
    }

    return self;    
}

这个函数的privateData参数是什么?不知道怎么设置参数...

现在 avcodec_decode_video2 返回 -1;

framedata 来成功了。

如何解决这个问题。

非常感谢。

【问题讨论】:

    标签: iphone ffmpeg h.264 decoding


    【解决方案1】:

    看看你的 ffmpeg 示例,在 PATH/TO/FFMPEG/doc/example/decoder_encoder.c 中, 这个链接:

    http://cekirdek.pardus.org.tr/~ismail/ffmpeg-docs/api-example_8c-source.html

    小心,这段代码太旧了,一些函数的名字已经改变了。

    【讨论】:

      猜你喜欢
      • 2017-04-23
      • 2016-11-10
      • 2011-11-24
      • 2011-03-30
      • 1970-01-01
      • 2011-08-26
      • 2020-06-13
      • 2015-06-03
      • 2014-07-03
      相关资源
      最近更新 更多