繁体   English   中英

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

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

我正在基于标准ffmpeg转码器示例使用ffmpeg库构建程序。 我的目标是建立视频转码器,将任何合适的视频(即ffmpeg可以读取)编码为WEBM格式。 问题是如何将选项传递给VP8编码器以控制输出视频质量和其他参数? 我的意思是通过C ++代码传递这些选项。

使用以下代码:

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);

相关的“选项” /“值”对可以从FFmpeg Wiki的vp8编码指南中获得。 例如,要将比特率设置为1 mbps(Wiki中的第一个示例),请使用:

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

要么

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

我建议使用VP9而不是VP8,使用VP8不会获得很好的质量,但这显然是您的选择。

暂无
暂无

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

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