doc/examples: fix output context cleanup in transcode examples

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 <barryjzhao@tencent.com>
This commit is contained in:
Jun Zhao
2026-03-08 22:44:17 +08:00
committed by toots
parent 34bff02984
commit 40f085ac3d
2 changed files with 6 additions and 2 deletions

View File

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

View File

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