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
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.
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
.