开发者

iPhone - A problem with decoding H264 using ffmpeg

I am working with ffmpeg to decode H264 stream from server.

I referenced DecoderWrapper from http://github.com/dropcam/dropcam_for_iphone.

I compiled it successfully, but I don't know how use it.

Here are the function that has problem.

- (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;    
}

What is the privateData parameter of this function? I don't know how to set the parameter...

Now avcodec_decode_video2 returns -1;

The framedata is coming successfully.

How solve this problem.

Thanks a lot.


Take a look at your ffmpeg example, where in PATH/TO/FFMPEG/doc/example/decoder_encoder.c, and this link:

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

Be careful, this code just too old, some function's name has already changed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜