[FFmpeg-devel] [PATCH 4/4] avcodec: vaapi_decode, do not set initial_pool_size if driver supports frame pool resizing

Xu Guangxin guangxin.xu at intel.com
Thu Nov 18 06:05:49 EET 2021


Two benifites of this commit:
1. Save memory. If we play an 8k hevc, previous code we allocate 50M * 20(1 + 16 + 3) = 1G memory. 4 may enough for most of playback usecases. 16 is a waste.
2. Allow downstream cache more frames. A downstream lookahead encoder will cache some frames. 20 may not enough for it.

This commit will fix the following command
ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -i 100frames.264  -vf reverse -an -f null -
---
 libavcodec/vaapi_decode.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 665af370ed..177949c36d 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -572,22 +572,24 @@ static int vaapi_decode_make_config(AVCodecContext *avctx,
         if (err < 0)
             goto fail;
 
-        frames->initial_pool_size = 1;
-        // Add per-codec number of surfaces used for storing reference frames.
-        switch (avctx->codec_id) {
-        case AV_CODEC_ID_H264:
-        case AV_CODEC_ID_HEVC:
-        case AV_CODEC_ID_AV1:
-            frames->initial_pool_size += 16;
-            break;
-        case AV_CODEC_ID_VP9:
-            frames->initial_pool_size += 8;
-            break;
-        case AV_CODEC_ID_VP8:
-            frames->initial_pool_size += 3;
-            break;
-        default:
-            frames->initial_pool_size += 2;
+        if (hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_FRAME_POOL_RESIZING) {
+            frames->initial_pool_size = 1;
+            // Add per-codec number of surfaces used for storing reference frames.
+            switch (avctx->codec_id) {
+            case AV_CODEC_ID_H264:
+            case AV_CODEC_ID_HEVC:
+            case AV_CODEC_ID_AV1:
+                frames->initial_pool_size += 16;
+                break;
+            case AV_CODEC_ID_VP9:
+                frames->initial_pool_size += 8;
+                break;
+            case AV_CODEC_ID_VP8:
+                frames->initial_pool_size += 3;
+                break;
+            default:
+                frames->initial_pool_size += 2;
+            }
         }
     }
 
-- 
2.25.1



More information about the ffmpeg-devel mailing list