[FFmpeg-devel] [PATCH 23/24] fftools/ffmpeg_mux: flush bsfs immediately on exceeding recoding time

Anton Khirnov anton at khirnov.net
Sun May 28 12:14:15 EEST 2023


Current code marks the output stream as finished and waits for a flush
packet, but that is both unnecessary and suspect, as in theory nothing
should be sent to a finished stream - not even flush packets.
---
 fftools/ffmpeg_mux.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 3da3c04d7f..feb014ca31 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -386,6 +386,11 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts)
     AVPacket *opkt = ost->pkt;
 
     av_packet_unref(opkt);
+
+    if (of->recording_time != INT64_MAX &&
+        dts >= of->recording_time + start_time)
+        pkt = NULL;
+
     // EOF: flush output bitstream filters.
     if (!pkt) {
         of_output_packet(of, opkt, ost, 1);
@@ -407,12 +412,6 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts)
             return;
     }
 
-    if (of->recording_time != INT64_MAX &&
-        dts >= of->recording_time + start_time) {
-        close_output_stream(ost);
-        return;
-    }
-
     if (av_packet_ref(opkt, pkt) < 0)
         exit_program(1);
 
-- 
2.40.1



More information about the ffmpeg-devel mailing list