iPhone - 使用 ffmpeg 解码 H264 的问题
我正在使用 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;
帧数据已成功传入。
怎么解决这个问题。
多谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看你的 ffmpeg 示例,在 PATH/TO/FFMPEG/doc/example/decoder_encoder.c 中,
以及此链接:
http://cekirdek.pardus。 org.tr/~ismail/ffmpeg-docs/api-example_8c-source.html
注意,这段代码太旧了,某些函数的名称已经更改了。
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.