From d25d6b991d0808856bc5803896739fc620ea0600 Mon Sep 17 00:00:00 2001 From: Jun Zhao Date: Mon, 9 Mar 2026 08:42:56 +0800 Subject: [PATCH] doc/examples/vaapi_encode: return raw error codes from encode_write encode_write() mapped all return values from avcodec_receive_packet() into 0 or -1, which destroyed the AVERROR_EOF signal needed by the caller. The flush call in main() could never see AVERROR_EOF, so a successful encode always exited with a non-zero status. Let encode_write() return the original error code and have each call site handle the expected status: - Encoding loop: ignore AVERROR(EAGAIN) (need more input) - Flush path: ignore AVERROR_EOF (normal end-of-stream) This makes the control flow explicit and easier to follow for anyone reading the example. Signed-off-by: Jun Zhao --- doc/examples/vaapi_encode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/examples/vaapi_encode.c b/doc/examples/vaapi_encode.c index d4381776ca..a27bb03da2 100644 --- a/doc/examples/vaapi_encode.c +++ b/doc/examples/vaapi_encode.c @@ -96,7 +96,6 @@ static int encode_write(AVCodecContext *avctx, AVFrame *frame, FILE *fout) end: av_packet_free(&enc_pkt); - ret = ((ret == AVERROR(EAGAIN)) ? 0 : -1); return ret; } @@ -198,7 +197,8 @@ int main(int argc, char *argv[]) goto close; } - if ((err = (encode_write(avctx, hw_frame, fout))) < 0) { + err = encode_write(avctx, hw_frame, fout); + if (err != AVERROR(EAGAIN) && err < 0) { fprintf(stderr, "Failed to encode.\n"); goto close; }