我有一个解码器代码。我正在尝试将其集成到 ffmpeg 框架
中。
我指的是此处给出的操作方法: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
中其他可用解码器的代码时,我发现每个解码器都定义了这一点。如果我不指定这个,我的解码器会工作吗?因此我无法继续。请提供一些重新分级的指导。
--提前致谢。
最佳答案
我维护着您链接到的 MultimediaWiki,并且我可以证明编解码器 HOWTO 已经过时,特别是因为 FFmpeg 始终在发展其内部接口(interface)。最好通过获取最新的 FFmpeg 源代码并研究一些最简单的编解码器来了解接口(interface)来开始您的旅程(听起来您已经这样做了)。
关于 priv_data_size:是否设置此项完全取决于您的编解码器是否关心在调用之间维护任何状态。大多数编解码器都关心这一点,并在其主源文件中定义一个结构,例如 MyCodecContext.然后 sizeof()
该结构作为 priv_data_size 传递。在您发布的示例中,它是 sizeof(COOKContext)
,因为这个示例显然是从 RealAudio COOK 编解码器文件复制的。
大多数编解码器需要维护某种状态(例如指向先前帧或各种表的指针)。 priv_data_size 成员告诉核心引擎为此结构分配多少空间,然后核心将该结构传递给所有编解码器调用。
关于video - FFMPEG:为编解码器定义上下文是强制性的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20259503/