Where to get full list of libav* formats?
Asked Answered
M

4

4

Where to get full list of libav* formats?

Mithgarthr answered 30/5, 2010 at 22:6 Comment(1)
see also What are all of the file extensions supported by FFmpegDecreasing
T
17

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);
}
Tomlin answered 12/6, 2012 at 9:52 Comment(1)
I wouldn't use 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
H
3

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

Hautemarne answered 30/5, 2010 at 22:18 Comment(0)
T
2

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
        }
    }
}
Tetrabranchiate answered 14/2, 2019 at 13:20 Comment(0)
D
0

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.

Downtrodden answered 31/12, 2023 at 17:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.