Translating ffmpeg command line to C++ codec setti

2019-02-27 17:11发布

问题:

I've been doing some work in ffmpeg for a while in C++. Most of the help regarding encoder settings is explained as command line options. For example (taken from the ffmpeg site):

-mbd rd -trellis 2 -cmp 2 -subcmp 2 -g 100 -pass 1/2’ 

but beware the ’-g 100’ might cause problems with some decoders. Things to try:

 ’-bf 2’, ’-flags qprd’, ’-flags mv0’, ’- flags skiprd.

This is not really usefull when you want to set these options in C. For example I managed to find int trellis; in the AVCodecContext struct so that is one solved, but what about the others?

Is there a way to determine what command line parameters correspond to what AVCodecContext members ? I tried setting them like this:

AVCodecContext* c;
av_opt_set_int(c->priv_data, "cmp", 2, 0);

But this returns an error code that the option does not exist. I've also tried:

  av_opt_set(c->priv_data, "cmp", "2", 0);

I still get the error that the option does not exist.

So, is there a way to determine what AVCodecContext members I should set that are equivalent to the ffmpeg command line parameters above ?

回答1:

You're doing it wrong™

av_opt_set (and friends) take an object of type AVClass (proof). Don't touch priv_data.

You should notice that AVCodecContext is an AVClass because it's first member is an AVClass (which is more or less how "inheritance" (to abuse the term) works in C).

In short, what you should be doing is:

AVCodecContext* c;
av_opt_set_int(c, "cmp", 2, 0);

If you want to know what options a particular class can take, just look at the source. For example, the libopenjpeg encoder takes many options. Other classes in avcodec/avformat define the options they take in a very similar way. These options are dumped out when you do ffmpeg's long help, but sometimes going to the source can shed some light on things.

Also, for future reference, and to help you, you might want to read this for how options that don't take parameters are set.



标签: c++ ffmpeg codec