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

后端 未结 2 1081
梦如初夏
梦如初夏 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<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
            }
        }
    }
    

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

    0 讨论(0)
  • 2021-01-15 14:08

    For each individual muxer, there is usually a codec tag writing function.That function will check against a list in another source file or work through a switch statement in the same. There is no central roster or container-matching utility function. Your best bet is to identify the codec id in libavcodec/allcodecs.c and then grep in libavformat/ for that ID, particularly within files suffixed with enc e.g. matroskaenc.c.

    0 讨论(0)
提交回复
热议问题