From 40f085ac3d12e7150f97dea70efd0f8ac9186d50 Mon Sep 17 00:00:00 2001 From: Jun Zhao Date: Sun, 8 Mar 2026 22:44:17 +0800 Subject: [PATCH] doc/examples: fix output context cleanup in transcode examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit avformat_close_input() is designed for input format contexts only. Using it on output contexts is API misuse — it accesses iformat (which is NULL for output contexts) and does not follow the correct output cleanup path. Replace with the proper pattern already used in remux.c and transcode.c: avio_closep() to close the IO handle, followed by avformat_free_context() to free the format context. Signed-off-by: Jun Zhao --- doc/examples/qsv_transcode.c | 4 +++- doc/examples/vaapi_transcode.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/examples/qsv_transcode.c b/doc/examples/qsv_transcode.c index c3f507e8e6..b4230e7a38 100644 --- a/doc/examples/qsv_transcode.c +++ b/doc/examples/qsv_transcode.c @@ -430,7 +430,9 @@ int main(int argc, char **argv) end: avformat_close_input(&ifmt_ctx); - avformat_close_input(&ofmt_ctx); + if (ofmt_ctx && !(ofmt_ctx->oformat->flags & AVFMT_NOFILE)) + avio_closep(&ofmt_ctx->pb); + avformat_free_context(ofmt_ctx); avcodec_free_context(&decoder_ctx); avcodec_free_context(&encoder_ctx); av_buffer_unref(&hw_device_ctx); diff --git a/doc/examples/vaapi_transcode.c b/doc/examples/vaapi_transcode.c index e1b7a43883..dba37d4bcb 100644 --- a/doc/examples/vaapi_transcode.c +++ b/doc/examples/vaapi_transcode.c @@ -294,7 +294,9 @@ int main(int argc, char **argv) end: avformat_close_input(&ifmt_ctx); - avformat_close_input(&ofmt_ctx); + if (ofmt_ctx && !(ofmt_ctx->oformat->flags & AVFMT_NOFILE)) + avio_closep(&ofmt_ctx->pb); + avformat_free_context(ofmt_ctx); avcodec_free_context(&decoder_ctx); avcodec_free_context(&encoder_ctx); av_buffer_unref(&hw_device_ctx);