Question

I'm having a a decoder code. I'm trying to integrate it into ffmpeg framework.

I'm referring to the HOW TO given here: http://wiki.multimedia.cx/index.php?title=FFmpeg_codec_howto

According to that article i need to define a structure in my decoder_name.c file.

The example structure is shown below:

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

Where,

.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.

However, my doubt is according to the above mentioned article, there is another field called .priv_data_size which hold the size of some context.

Is it compulsory to have this field .priv_data_size because according to the above article, i need not define all the parameters of the structure AVCodec. Further i do not possess any such context for my decoder.

However, when i go through the code of other available decoders in libavcodec of ffmpeg, i find that every decoder has defined this. Will my decoder work if i do not specify this? I'm unable to proceed because of this. please provide some guidance regrading the same.

--Thanks in advance.

Was it helpful?

Solution

I maintain the MultimediaWiki you linked to and I can attest that the codec HOWTO is out of date, especially since FFmpeg is always evolving its internal interfaces. It would be best to start your journey by getting the latest FFmpeg source code and studying a few of the simplest codecs to understand the interface (sounds like you have already been doing this).

About priv_data_size: whether you set this depends entirely on whether your codec cares about maintaining any state between calls. Most codecs care about this and define a structure in their main source file named, e.g., MyCodecContext. Then the sizeof() this structure is passed as priv_data_size. In the example you posted, it was sizeof(COOKContext), because this example was clearly copied from the RealAudio COOK codec file.

Most codecs need to maintain some kind of state (like pointers to previous frames or various tables). The priv_data_size member tells the core engine how much space to allocate for this structure and then the core passes that structure to all the codec calls.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top