PR #25970 opened by Anton Kesy (antonkesy) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25970 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25970.patch
## Description When the last input frame and the EOF are consumed in the same `activate()` call, vpp_qsv loses the last frame. `activate()` sets `qsv->eof` as soon as it acknowledges the EOF, before the frame is submitted. `ff_qsvvpp_filter_frame()` then: 1. drains the async fifo (`while (s->eof && av_fifo_read(...))`), 2. submits the last frame, which is queued in the async fifo, and `activate()` jumps to `eof` and forwards the EOF to the output link. The frame that was just queued is never output. A buffersrc delivers the EOF in a separate activation, so a single vpp_qsv is not affected. Any filter that returns its last frame together with the EOF triggers it, for example a second vpp_qsv. The fix drains the async fifo once more after the last frame was submitted, then forwards the EOF. `scale_qsv` and `deinterlace_qsv` share this `activate()` and get the same fix. ### Reproduce The input is any 720-frame H.264 clip (1920x800, 24 fps): ```sh ffmpeg -hwaccel qsv -hwaccel_output_format qsv -i in.mkv -an \ -vf vpp_qsv=w=1280:h=536,vpp_qsv=transpose=clock \ -c:v hevc_qsv -preset veryfast out.mkv ffprobe -v error -count_packets -select_streams v:0 \ -show_entries stream=nb_read_packets -of csv=p=0 out.mkv ``` | filter chain | before | after | |---|---|---| | `vpp_qsv=w=1280:h=536` | 720 | 720 | | `vpp_qsv=w=1280:h=536,vpp_qsv=transpose=clock` | **719** | 720 | Tested on Win 11, Intel Core Ultra 7 366H (32.0.101.8517) with oneVPL API 2.17, implementation 2.16 (D3D11). But this patch should be runtime-independent. >From 1aca42b3782aa35525355f8724d15ed5adac4bf1 Mon Sep 17 00:00:00 2001 From: Anton Kesy <[email protected]> Date: Thu, 12 Nov 2026 13:04:50 +0100 Subject: [PATCH] avfilter/vf_vpp_qsv: drain the last frame received with the eof When the last input frame and the eof are consumed in the same activation, qsv->eof is set before the frame is submitted, so ff_qsvvpp_filter_frame() drains the queued frames first, then submits the last frame, and activate() forwards the eof right away. The last frame stays in the async fifo and is lost. This happens whenever the upstream filter returns its last frame and the eof together, e.g. a vpp_qsv after another vpp_qsv, and the output is one frame short. Drain the async fifo again after the last frame is submitted. Signed-off-by: Anton Kesy <[email protected]> --- libavfilter/vf_vpp_qsv.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c index 4de99d6490d..7da8b806d93 100644 --- a/libavfilter/vf_vpp_qsv.c +++ b/libavfilter/vf_vpp_qsv.c @@ -753,13 +753,20 @@ static int activate(AVFilterContext *ctx) if (in || qsv->eof) { ret = ff_qsvvpp_filter_frame(qsv, inlink, in, in); av_frame_free(&in); - if (ret == AVERROR(EAGAIN)) - goto not_ready; - else if (ret < 0) + if (ret < 0 && ret != AVERROR(EAGAIN)) return ret; - if (qsv->eof) + if (qsv->eof) { + /* The last frame can come with the eof, it was submitted + * after the queued frames were drained, drain it too */ + ret = ff_qsvvpp_filter_frame(qsv, inlink, NULL, NULL); + if (ret < 0) + return ret; goto eof; + } + + if (ret == AVERROR(EAGAIN)) + goto not_ready; if (qsv->got_frame) { qsv->got_frame = 0; -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
