我正在使用 C/C++ 中的 FFMpeg 库开发媒体播放器。
This source使用以下代码查找文件中视频流的解码器:
pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
,
其中 pCodecCtx 是指向视频流的编解码器上下文的指针,pCodec 是指向初始化为 NULL 的 AVCodec 的指针。
如果我们必须显式地找到解码器,那么在struct AVCodecContext
中找到的struct AVCodec *codec
是什么?这是定义 here .有人可以帮我了解它的用途吗?
最佳答案
AVCodec 是一个结构体,用于保存有关编解码器的信息,例如编解码器名称等。
参见 here定义。
如果您想阅读网站上列出的 muxing.c 示例,他们使用 AVCodec 本身来初始化 AVCodecContext 中的 AVCodec。
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;
关于ffmpeg - "struct AVCodec *codec"中的 "struct AVCodecContext"代表什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16985847/