Skip to content

Commit

Permalink
avcodec: vaapi_decode, do not set initial_pool_size if driver support…
Browse files Browse the repository at this point in the history
…s frame pool resizing

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.16 is a waste for most playback cases.
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 -
  • Loading branch information
xuguangxin committed Jul 7, 2021
1 parent 7844644 commit d8388a5
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions libavcodec/vaapi_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
frames->initial_pool_size += 16;
break;
case AV_CODEC_ID_VP9:
case AV_CODEC_ID_AV1:
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:
frames->initial_pool_size += 16;
break;
case AV_CODEC_ID_VP9:
case AV_CODEC_ID_AV1:
frames->initial_pool_size += 8;
break;
case AV_CODEC_ID_VP8:
frames->initial_pool_size += 3;
break;
default:
frames->initial_pool_size += 2;
}
}
}

Expand Down

0 comments on commit d8388a5

Please sign in to comment.