0

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

4

1 回答 1

1

使用以下代码:

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 你不会得到很好的质量,但这显然是你的选择。

于 2016-06-28T20:00:34.180 回答