3

Where to get full list of libav* formats?

Rella
  • 59,216
  • 102
  • 341
  • 614

3 Answers3

15

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);
}
Rob
  • 3,872
  • 3
  • 28
  • 25
  • 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. – Bim Feb 14 '19 at 13:22
2

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

Michael Chinen
  • 14,687
  • 4
  • 29
  • 45
0

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
        }
    }
}
Bim
  • 866
  • 1
  • 9
  • 28