ffmpeg - "struct AVCodec *codec"中的 "struct AVCodecContext"代表什么?

标签 ffmpeg media-player decoder

我正在使用 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/

相关文章:

node.js - 在 Node.js 中使用 ffmpeg 将图像放在视频上

java - 如何停止 Android 中的 Activity ?

java - 空对象引用上的 android.media.MediaPlayer.start()'

android - 解码的AAC声音为AudioTrack奇怪的声音

voip - 将 .raw voip 数据解码为 opus

c# - 使用 FFMPEG (C#) 从视频中获取特定帧

ffmpeg DASH 编码 : always getting bitrate as 200k for vp9 codec

android - 如何检查 MediaPlayer 是否已停止?

android - 在 Android 中使用 Opus Codec 进行录制和播放

html - 实时流式传输 RTMP 到 HTML5