How can I determine if a codec / container combination is compatible with FFmpeg?

后端 未结 2 1083
梦如初夏
梦如初夏 2021-01-15 13:09

I\'m looking at re-muxing some containers holding audio and video such that I extract the best, first audio stream, and store it in a new container where e.g. only

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-15 14:06

    There's a dynamic approach to that problem. This enumerates the codecs for each container, but you also get the inverse:

    // enumerate all codecs and put into list
    std::vector 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
            }
        }
    }
    

    If you just want specific containers or codecs you can use a whitelist with their name or id fields and use that when enumerating.

提交回复
热议问题