将 YUV420 帧编码为 VP9

encode YUV420 frame to VP9

如题,

我正在从网络摄像机中提取帧。我将输入的原始数据转换为YUV420格式,并想将YUV420编码为VP9,并将帧保存为.webm格式。我能做到吗?或者我应该输入 BGR444 格式进行编码?

顺便说一句,设置编码vp9的参数。 av_dict_set()是设置参数的正确函数吗?

例如:(http://wiki.webmproject.org/ffmpeg/vp9-encoding-guide)

av_dict_set(&opt, "crf"    , "23", 0);
av_dict_set(&opt, "speed"  , "4" , 0);
av_dict_set(&opt, "threads", "8" , 0);
av_dict_set(&opt, "pass"   , "1" , 0);
av_dict_set(&opt, "b:v", "1400k", 0);

编辑:wiki 使用 2 遍设置参数,我可以通过 1 遍完成吗?

Edit2:Blow 代码似乎有效,想知道如何降低视频 (vp9) 的大小?目前,我的尺寸与使用 h264 编码器的尺寸相似。

    av_dict_set(&opt, "crf"    ,        "45", 0);  
    av_dict_set(&opt, "speed"  ,        "8" , 0); 
    av_dict_set(&opt, "quality",        "realtime", 0);
    av_dict_set(&opt, "threads",        "8" , 0);
    av_dict_set(&opt, "tile-columns",   "3", 0);
    av_dict_set(&opt, "frame-parallel", "1", 0);
    av_dict_set(&opt, "row-mt",         "1", 0);

更新1: YUV420P可以编码为VP9!

I'm pulling frames from a IP camera. I converted the input raw data to YUV420 format, and would like to encode YUV420 to VP9, and save frames as .webm format. Would I be able to do that?

是的。这里是ffmpeg的官方例子:https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples

Or should I input a BGR444 format for encoding?

始终使用 yuv 格式,例如 yuv420p。不要用RGB,即使支持也会很低效

The wiki uses 2 pass for setting parameters, would I be able to do in with 1 pass

是的,2 pass 有优势但不是必需的。

Blow code seems to be working, wonder how can I bring the size of the videos (vp9) down? Currently, I have similar size as using h264 encoder.

您需要的是 ffmpeg 的 sws_scale 功能。这会做两件事,缩放和格式转换,两者可以同时执行。检查 scaling_video.c 示例。