【问题标题】:What does the "struct AVCodec *codec" in "struct AVCodecContext" represent?“struct AVCodecContext”中的“struct AVCodec *codec”代表什么?
【发布时间】:2013-06-03 20:43:48
【问题描述】:

我正在使用 C/C++ 中的 FFMpeg 库来开发媒体播放器。
This source 使用以下代码在文件中查找视频流的解码器:

pCodec=avcodec_find_decoder(pCodecCtx->codec_id);,

其中 pCodecCtx 是指向视频流的编解码器上下文的指针,而 pCodec 是指向初始化为 NULL 的 AVCodec 的指针。

如果我们必须显式找到解码器,那么在struct AVCodecContext 中找到的struct AVCodec *codec 是什么?这是定义 here 。有人可以帮我理解它的用途吗?

【问题讨论】:

    标签: ffmpeg media-player decoder


    【解决方案1】:

    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;
    
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-26
      • 2011-11-14
      • 1970-01-01
      • 1970-01-01
      • 2016-03-03
      • 2014-06-17
      • 1970-01-01
      相关资源
      最近更新 更多