PR #24780 opened by ffmpeg-devel
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24780
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24780.patch

**Backport:** https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24665

So far, if an avformats write_trailer call returned a positive value instead of 
0, like for example movenc does for the number of bytes written, it would hide 
any pb context failures.
This adjusts the check to expect positive return values, and only overwrites 
them with the pb error if it actually had an error, to preserve the return 
value in case something came to rely on it.


>From b4a62c32549b8295691a8e0ff2c9b82188923159 Mon Sep 17 00:00:00 2001
From: Timo Rothenpieler <[email protected]>
Date: Thu, 24 Sep 2026 14:21:41 +0200
Subject: [PATCH] avformat/mux: don't let positive write_trailer ret shadow pb
 failure

(cherry picked from commit 1de217ad4b98163b7f5a372853b1c943ed6f070d)
---
 libavformat/avformat.h | 2 +-
 libavformat/mux.c      | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 1916aa2dc5..f96a84fce6 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -2388,7 +2388,7 @@ int av_write_uncoded_frame_query(AVFormatContext *s, int 
stream_index);
  * May only be called after a successful call to avformat_write_header.
  *
  * @param s media file handle
- * @return 0 if OK, AVERROR_xxx on error
+ * @return >=0 if OK, AVERROR_xxx on error
  */
 int av_write_trailer(AVFormatContext *s);
 
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 04de05ec17..5ffb9159ae 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -1286,8 +1286,8 @@ int av_write_trailer(AVFormatContext *s)
 
     if (s->pb)
        avio_flush(s->pb);
-    if (ret == 0)
-       ret = s->pb ? s->pb->error : 0;
+    if (ret >= 0 && s->pb && s->pb->error < 0)
+       ret = s->pb->error;
     for (unsigned i = 0; i < s->nb_streams; i++) {
         av_freep(&s->streams[i]->priv_data);
         av_freep(&ffstream(s->streams[i])->index_entries);
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to