3

I am using FFMpeg libraries in C/C++ to develop a media player .
This source uses the following code to find the decoder of a video stream in a file :

pCodec=avcodec_find_decoder(pCodecCtx->codec_id); ,

where pCodecCtx is the pointer to the Codec Context of the video stream and pCodec is a pointer to AVCodec which was initialised to NULL .

If we have to explicitly find the decoder , then what is the struct AVCodec *codec found in struct AVCodecContext ? This is defined here . Can someone please help me understand it's use .

progammer
  • 1,951
  • 11
  • 28
  • 50

1 Answers1

0

The AVCodec is a struct used to hold information about the codec such as codec name, etc.

See here for definition.

If you want to read the muxing.c example listed on the site, they use the AVCodec by itself to initialize the AVCodec within the AVCodecContext.

AVCodec *codec;
AVCodecID codec_id; // <-enum value (found based on the codec you enter)
AVCodecContext context;

//find and set encoder (or decoder) based on codec ID
codec = avcodec_find_encoder(codec_id);

//       or
// codec = avcodec_find_decoder(codec_id);

//Allocate encoding context for the AVCodec within AVCodecContext
context = avcodec_alloc_context3(*codec);

//Set the codec_id within AVCodecContext.
context->codec_id = codec_id;


Siong Thye Goh
  • 3,518
  • 10
  • 23
  • 31