从哪里获取 libav* 格式的完整列表?

发布于 2024-09-04 06:17:48 字数 28 浏览 1 评论 0原文

从哪里获取 libav* 格式的完整列表?

Where to get full list of libav* formats?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

分開簡單 2024-09-11 06:17:48

既然您要求 libav* 格式,我猜您正在寻找代码示例。

要获取所有编解码器的列表,请使用 av_codec_next api 迭代可用编解码器的列表。

/* initialize libavcodec, and register all codecs and formats */
av_register_all();

/* Enumerate the codecs*/
AVCodec * codec = av_codec_next(NULL);
while(codec != NULL)
{
    fprintf(stderr, "%s\n", codec->long_name);
    codec = av_codec_next(codec);
}

要获取格式列表,请以相同的方式使用 av_format_next:

AVOutputFormat * oformat = av_oformat_next(NULL);
while(oformat != NULL)
{
    fprintf(stderr, "%s\n", oformat->long_name);
    oformat = av_oformat_next(oformat);
}

如果您还想找出特定格式的推荐编解码器,您可以迭代编解码器标签列表:

AVOutputFormat * oformat = av_oformat_next(NULL);
while(oformat != NULL)
{
    fprintf(stderr, "%s\n", oformat->long_name);
    if (oformat->codec_tag != NULL)
    {
        int i = 0;

        CodecID cid = CODEC_ID_MPEG1VIDEO;
        while (cid != CODEC_ID_NONE) 
        {
            cid = av_codec_get_id(oformat->codec_tag, i++);
            fprintf(stderr, "    %d\n", cid);
        }
    }
    oformat = av_oformat_next(oformat);
}

Since you asked for libav* formats, I'm guessing you're after a code example.

To get a list of all the codecs use the av_codec_next api to iterate through the list of available codecs.

/* initialize libavcodec, and register all codecs and formats */
av_register_all();

/* Enumerate the codecs*/
AVCodec * codec = av_codec_next(NULL);
while(codec != NULL)
{
    fprintf(stderr, "%s\n", codec->long_name);
    codec = av_codec_next(codec);
}

To get a list of the formats, use av_format_next in the same way:

AVOutputFormat * oformat = av_oformat_next(NULL);
while(oformat != NULL)
{
    fprintf(stderr, "%s\n", oformat->long_name);
    oformat = av_oformat_next(oformat);
}

If you want to also find out the recommended codecs for a particular format, you can iterate the codec tags list:

AVOutputFormat * oformat = av_oformat_next(NULL);
while(oformat != NULL)
{
    fprintf(stderr, "%s\n", oformat->long_name);
    if (oformat->codec_tag != NULL)
    {
        int i = 0;

        CodecID cid = CODEC_ID_MPEG1VIDEO;
        while (cid != CODEC_ID_NONE) 
        {
            cid = av_codec_get_id(oformat->codec_tag, i++);
            fprintf(stderr, "    %d\n", cid);
        }
    }
    oformat = av_oformat_next(oformat);
}
甜心小果奶 2024-09-11 06:17:48

这取决于它的配置方式。构建 libavformat 时会显示一个列表。如果您已构建 ffmpeg,您还可以通过输入 ffmpeg -formats 来查看该列表。
此处还有所有支持格式的列表

This depends on how it is configured. A list is shown when you built libavformat. You can also see the list by typing ffmpeg -formats if you have ffmpeg built.
There is also a list for all supported formats here

甲如呢乙后呢 2024-09-11 06:17:48

我不建议使用编解码器标签列表来查找适合容器的编解码器。该接口(av_codec_get_idav_codec_get_tag2)超出了我的理解范围,它对我不起作用。更好地枚举和匹配所有编解码器和容器:

// enumerate all codecs and put into list
std::vector<AVCodec*> encoderList;
AVCodec * codec = nullptr;
while (codec = av_codec_next(codec))
{
    // try to get an encoder from the system
    auto encoder = avcodec_find_encoder(codec->id);
    if (encoder)
    {
        encoderList.push_back(encoder);
    }
}
// enumerate all containers
AVOutputFormat * outputFormat = nullptr;
while (outputFormat = av_oformat_next(outputFormat))
{
    for (auto codec : encoderList)
    {
        // only add the codec if it can be used with this container
        if (avformat_query_codec(outputFormat, codec->id, FF_COMPLIANCE_STRICT) == 1)
        {
            // add codec for container
        }
    }
}

I would not recommend using the codecs tag list to find the suitable codecs for a container. The interface (av_codec_get_id, av_codec_get_tag2) is beyond my comprehension and it didn't work for me. Better enumerate and match all codecs and containers:

// enumerate all codecs and put into list
std::vector<AVCodec*> encoderList;
AVCodec * codec = nullptr;
while (codec = av_codec_next(codec))
{
    // try to get an encoder from the system
    auto encoder = avcodec_find_encoder(codec->id);
    if (encoder)
    {
        encoderList.push_back(encoder);
    }
}
// enumerate all containers
AVOutputFormat * outputFormat = nullptr;
while (outputFormat = av_oformat_next(outputFormat))
{
    for (auto codec : encoderList)
    {
        // only add the codec if it can be used with this container
        if (avformat_query_codec(outputFormat, codec->id, FF_COMPLIANCE_STRICT) == 1)
        {
            // add codec for container
        }
    }
}
无可置疑 2024-09-11 06:17:48

2023 年,@Bim 的答案使用 ffmpeg 6 进行了更新:

std::vector<const AVCodec*> codecs;

// Iterate through the codecs
void* opaque = nullptr;
while(auto codec = av_codec_iterate(&opaque))
{ codecs.push_back(codec); }

// Iterate through the formats
opaque = nullptr;
while(auto format = av_muxer_iterate(&opaque))
{
  for(auto codec : codecs)
  {
    if(avformat_query_codec(format, codec.codec->id, FF_COMPLIANCE_STRICT) == 1) 
    {
      // Here you have a codec which matches with a muxing format 
    }
  }
}

av_demuxer_iterate 对于解复用器的工作方式相同。

In 2023, @Bim's answer updated with ffmpeg 6:

std::vector<const AVCodec*> codecs;

// Iterate through the codecs
void* opaque = nullptr;
while(auto codec = av_codec_iterate(&opaque))
{ codecs.push_back(codec); }

// Iterate through the formats
opaque = nullptr;
while(auto format = av_muxer_iterate(&opaque))
{
  for(auto codec : codecs)
  {
    if(avformat_query_codec(format, codec.codec->id, FF_COMPLIANCE_STRICT) == 1) 
    {
      // Here you have a codec which matches with a muxing format 
    }
  }
}

av_demuxer_iterate works the same way for demuxers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文