项目中用到ffmpeg进行编码,根据ffmpeg example代码 vaapi_encode.c进行编码,发现有些分辨率可以,有些分辨率会花屏,如下:
dump了编码前的数据,没有问题,所以肯定出在编码阶段,多试了一些分辨率,发现了规律,正常的视频的分辨率宽是32的倍数,花屏的视频的分辨率的宽不是32的倍数,之前一直对av_frame_get_buffer的第二个参数不太理解,但是根据现象,肯定是这个值有问题了
err = av_frame_get_buffer(sw_frame, 32)
代码里的注释为:
* @param frame frame in which to store the new buffers.
* @param align Required buffer size alignment. If equal to 0, alignment will be
* chosen automatically for the current CPU. It is highly
* recommended to pass 0 here unless you know what you are doing.
*
* @return 0 on success, a negative AVERROR on error.
*/
int av_frame_get_buffer(AVFrame *frame, int align);
所以测试,改为0,仍然不行。
网上搜索,搜到了已经有人踩过坑了。。。。
https://blog.csdn.net/grafx/article/details/29185147
这篇blog写的很好,看完就知道应该怎么设置第二个参数了