Where to get full list of libav* formats?
Since you asked for libav* formats, I'm guessing you're after a code example.
To get a list of all the codecs use the av_codec_next api to iterate through the list of available codecs.
/* 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);
}
To get a list of the formats, use av_format_next in the same way:
AVOutputFormat * oformat = av_oformat_next(NULL);
while(oformat != NULL)
{
fprintf(stderr, "%s\n", oformat->long_name);
oformat = av_oformat_next(oformat);
}
If you want to also find out the recommended codecs for a particular format, you can iterate the codec tags list:
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);
}
av_codec_get_id
to find the recommeded codecs. I'm not even sure your code is correct (taking a look at the FFmpeg source code), but it also didn't work for me. See my answer for an approach that worked for me. –
Tetrabranchiate This depends on how it is configured. A list is shown when you built libavformat. You can also see the list by typing ffmpeg -formats
if you have ffmpeg built.
There is also a list for all supported formats here
I would not recommend using the codecs tag list to find the suitable codecs for a container. The interface (av_codec_get_id
, av_codec_get_tag2
) is beyond my comprehension and it didn't work for me. Better enumerate and match all codecs and containers:
// 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
}
}
}
In 2023, @Bim's answer updated with ffmpeg 6:
std::vector<const AVCodec*> codecs;
// Iterate through the codecs
void* opaque = nullptr;
while(auto codec = av_codec_iterate(&opaque))
{ codecs.push_back(codec); }
// Iterate through the formats
opaque = nullptr;
while(auto format = av_muxer_iterate(&opaque))
{
for(auto codec : codecs)
{
if(avformat_query_codec(format, codec.codec->id, FF_COMPLIANCE_STRICT) == 1)
{
// Here you have a codec which matches with a muxing format
}
}
}
av_demuxer_iterate
works the same way for demuxers.
© 2022 - 2024 — McMap. All rights reserved.