哪里可以获得libav *格式的完整列表?

问题描述 投票:3回答:3

哪里可以获得libav *格式的完整列表?

list formats libav
3个回答
14
投票

既然你要求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);
}

2
投票

这取决于它的配置方式。构建libavformat时会显示一个列表。如果你已经构建了ffmpeg,你也可以通过输入ffmpeg -formats来查看列表。所有支持的格式here都有一个列表


0
投票

我不建议使用编解码器标签列表来查找容器的合适编解码器。界面(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
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.