简体   繁体   English

将ffmpeg命令行转换为C ++编解码器设置

[英]Translating ffmpeg command line to C++ codec settings

I've been doing some work in ffmpeg for a while in C++. 我在C ++中已经在ffmpeg中做了一些工作。 Most of the help regarding encoder settings is explained as command line options. 有关编码器设置的大多数帮助都解释为命令行选项。 For example (taken from the ffmpeg site): 例如(取自ffmpeg网站):

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

but beware the '-g 100' might cause problems with some decoders. 但请注意,“-g 100”可能会导致某些解码器出现问题。 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; 当您想在C中设置这些选项时,这并不是真正有用的方法 in the AVCodecContext struct so that is one solved, but what about the others? AVCodecContext结构中,这是一个已解决的问题,但其他问题又如何呢?

Is there a way to determine what command line parameters correspond to what AVCodecContext members ? 有没有一种方法可以确定哪些命令行参数与哪些AVCodecContext成员相对应? 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 ? 因此,有没有办法确定我应该设置哪些AVCodecContext成员,这些成员与上面的ffmpeg命令行参数等效?

You're doing it wrong™ 您做错了™

av_opt_set (and friends) take an object of type AVClass ( proof ). av_opt_set (和朋友)采用AVClass类型的对象( 证明 )。 Don't touch priv_data . 不要触摸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). 您应该注意到, AVCodecContextAVClass因为它的第一个成员是AVClass (这或多或少是“继承”(滥用术语)在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 . 例如,libopenjpeg编码器采用许多选项 Other classes in avcodec/avformat define the options they take in a very similar way. avcodec / avformat中的其他类以非常相似的方式定义它们所采用的选项。 These options are dumped out when you do ffmpeg's long help, but sometimes going to the source can shed some light on things. 当您执行ffmpeg的长期帮助时,这些选项将被放弃,但有时可以从源头上了解一些情况。

Also, for future reference, and to help you, you might want to read this for how options that don't take parameters are set. 另外,为了将来参考并为您提供帮助,您可能需要阅读本节 ,了解如何设置不带参数的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM