2013-11-28 30 views
2

我有一个解码器代码。我正试图将它整合到ffmpeg frameworkFFMPEG:是为编解码器强制定义上下文吗?

我指的是该怎么这里给出:http://wiki.multimedia.cx/index.php?title=FFmpeg_codec_howto

据该文章中,我需要在我decoder_name.c文件中定义的结构。

示例结构如下所示:

AVCodec sample_decoder = 
{ 
    .name   = "sample", 
    .type   = AVCODEC_TYPE_VIDEO, 
    .id    = AVCODEC_ID_SAMPLE, 
    // .priv_data_size = sizeof(COOKContext), 
    .init   = sample_decode_init, 
    .close   = sample_decode_close, 
    .decode   = sample_decode_frame, 
}; 

.name -> specifies the short name of my decoder. 

.type -> is used to specify that it is a video decoder. 

.id -> is an unique id that i'm assigning to my video decoder. 

.init -> is a function pointer to the function in my decoder code that performs decoder related initializations 

.decode -> is a function pointer to the function in my decoder code that decodes a single frame, given the input data (elementary stream). 

.close -> is a function pointer to the function in my decoder that frees all allocated memory i.e. the memory allocated in init. 

然而,我的疑问是根据上述文章,还有一个字段称为.priv_data_size持有的大小一些背景。

是否必须拥有此字段.priv_data_size,因为根据上面的文章,我不需要定义结构AVCodec的所有参数。此外,我没有任何这样的上下文为我的解码器。但是,当我通过ffmpeg的libavcodec中的其他可用解码器的代码时,我发现每个解码器都定义了这个。如果我没有指定这个,我的解码器能工作吗?因为这个,我无法继续。请提供一些相同的指导。

- 提前感谢。

回答

3

我维护您链接到的MultimediaWiki,并且我可以证明编解码器HOWTO已过时,尤其是因为FFmpeg总是在不断发展其内部接口。最好是通过获取最新的FFmpeg源代码并研究一些最简单的编解码器来了解接口(听起来像你已经这样做了),开始你的旅程。

关于priv_data_size:是否设置此取决于您的编解码器是否在维护呼叫之间的任何状态。大多数编解码器关心这一点,并在其主要源文件中定义一个名为MyCodecContext的结构。然后sizeof()这个结构作为priv_data_size传递。在你发布的例子中,它是sizeof(COOKContext),因为这个例子显然是从RealAudio COOK编解码器文件中复制的。大多数编解码器需要维护某种状态(如指向先前帧或各种表的指针)。 priv_data_size成员告诉核心引擎需要为此结构分配多少空间,然后核心将该结构传递给所有编解码器调用。

+0

很高兴听到您是维护该帖子的人。它真的帮助像我这样的人开始使用编解码器集成。首先感谢这篇文章和你的回答。其次,如果您确实有任何此类相关帖子,请在本节中提供您的宝贵帖子链接。这对每个人都有帮助。谢谢:) – sam

+0

这里是我写的另一篇文章,以回应一系列与多媒体有关的问题,可能会感兴趣:http://stackoverflow.com/a/9958424/475067 –