3

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

4

3 回答 3

16

由于您要求 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);
}
于 2012-06-12T09:52:35.203 回答
3

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

于 2010-05-30T22:18:45.477 回答
0

我不建议使用编解码器标签列表来为容器找到合适的编解码器。界面(av_codec_get_id, av_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
        }
    }
}
于 2019-02-14T13:20:41.243 回答