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