简体   繁体   English

如何在基于ffmpeg的程序中以编程方式传递VP8编码器选项

[英]How to pass VP8 encoder option programmatically in ffmpeg based program

I am building a program using ffmpeg libraries based on the standard ffmpeg transcoder example. 我正在基于标准ffmpeg转码器示例使用ffmpeg库构建程序。 My aim is to build video transcoder which encodes any suitable video (ie which ffmpeg can read) into WEBM format. 我的目标是建立视频转码器,将任何合适的视频(即ffmpeg可以读取)编码为WEBM格式。 The question is how do I pass options to VP8 encoder to control output video quality and other parameters? 问题是如何将选项传递给VP8编码器以控制输出视频质量和其他参数? I mean passing these option via C++ code. 我的意思是通过C ++代码传递这些选项。

Use the following code: 使用以下代码:

AVDictionary *options = NULL;
AVCodec *codec = avcodec_find_encoder(AVCODEC_ID_VP8);
AVCodecContext *ctx = avcodec_alloc_context3(codec);

av_dict_set(&options, "option", "value", 0);

int res = avcodec_open2(ctx, codec, &options);
if (res < 0)
    error();

while (..) {
    res = avcodec_encode_video2(ctx, ..);
    if (res < 0)
        error();
}

avcodec_close(ctx);
avcodec_free_context(ctx);

The relevant "option"/"value" pairs are whatever you would get from the vp8 encoding guides from eg the FFmpeg wiki. 相关的“选项” /“值”对可以从FFmpeg Wiki的vp8编码指南中获得。 For example, to set a bitrate of 1 mbps (first example in wiki), use: 例如,要将比特率设置为1 mbps(Wiki中的第一个示例),请使用:

av_dict_set_int(&options, "b", 1024 * 1024, 0);

or 要么

av_dict_set(&options, "b", "1M", 0);

I recommend to use VP9 instead of VP8, you won't get great quality with VP8, but that's obviously your choice. 我建议使用VP9而不是VP8,使用VP8不会获得很好的质量,但这显然是您的选择。

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

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