[FFmpeg-cvslog] avcodec/vaapi_encode_vp9: fix > 4k encode fail issue

Zhang yuankun git at videolan.org
Mon Dec 27 06:22:23 EET 2021


ffmpeg | branch: master | Zhang yuankun <yuankunx.zhang at intel.com> | Mon Apr 12 09:47:24 2021 +0800| [db901276c0ae4799a0d2c8f81f09497dd66b4ed7] | committer: Haihao Xiang

avcodec/vaapi_encode_vp9: fix > 4k encode fail issue

This patch will fix following command:
ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -i input.264 \
-vf 'scale_vaapi=w=7680:h=4096' -c:v vp9_vaapi output.ivf

Max width of a vp9 tile is 4096. If the source frame > 4096, we need split to multiple tiles.

Reviewed-by: Limin Wang <lance.lmwang at gmail.com>
Signed-off-by: Zhang yuankun <yuankunx.zhang at intel.com>
Signed-off-by: Haihao Xiang <haihao.xiang at intel.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=db901276c0ae4799a0d2c8f81f09497dd66b4ed7
---

 libavcodec/vaapi_encode_vp9.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c
index b3f45fb8fe..be706e3bd6 100644
--- a/libavcodec/vaapi_encode_vp9.c
+++ b/libavcodec/vaapi_encode_vp9.c
@@ -31,6 +31,7 @@
 
 #define VP9_MAX_QUANT 255
 
+#define VP9_MAX_TILE_WIDTH 4096
 
 typedef struct VAAPIEncodeVP9Picture {
     int slot;
@@ -82,10 +83,17 @@ static int vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx,
     VAAPIEncodeVP9Picture          *hpic = pic->priv_data;
     VAEncPictureParameterBufferVP9 *vpic = pic->codec_picture_params;
     int i;
+    int num_tile_columns;
 
     vpic->reconstructed_frame = pic->recon_surface;
     vpic->coded_buf = pic->output_buffer;
 
+    // Maximum width of a tile in units of superblocks is MAX_TILE_WIDTH_B64(64)
+    // So the number of tile columns is related to the width of the picture.
+    // We set the minimum possible number for num_tile_columns as default value.
+    num_tile_columns = (vpic->frame_width_src + VP9_MAX_TILE_WIDTH - 1) / VP9_MAX_TILE_WIDTH;
+    vpic->log2_tile_columns = num_tile_columns == 1 ? 0 : av_log2(num_tile_columns - 1) + 1;
+
     switch (pic->type) {
     case PICTURE_TYPE_IDR:
         av_assert0(pic->nb_refs == 0);



More information about the ffmpeg-cvslog mailing list