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 <barryjzhao@tencent.com>
This commit is contained in:
Jun Zhao
2026-03-09 08:42:56 +08:00
committed by toots
parent 8d80b13cbe
commit d25d6b991d

View File

@@ -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;
}