[FFmpeg-cvslog] fftools/ffmpeg_mux: factor timestamps processing out of write_packet()

Anton Khirnov git at videolan.org
Mon Dec 18 09:54:02 EET 2023


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Thu Dec 14 13:51:27 2023 +0100| [7a7550ec28a23761055a142f448d3cb592b2c726] | committer: Anton Khirnov

fftools/ffmpeg_mux: factor timestamps processing out of write_packet()

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7a7550ec28a23761055a142f448d3cb592b2c726
---

 fftools/ffmpeg_mux.c | 50 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 30 insertions(+), 20 deletions(-)

diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 3ce4ef131e..88ce3cd60c 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -135,20 +135,9 @@ static void mux_log_debug_ts(OutputStream *ost, const AVPacket *pkt)
            pkt->size, *latency ? latency : "N/A");
 }
 
-static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
+static int mux_fixup_ts(Muxer *mux, MuxStream *ms, AVPacket *pkt)
 {
-    MuxStream *ms = ms_from_ost(ost);
-    AVFormatContext *s = mux->fc;
-    int64_t fs;
-    uint64_t frame_num;
-    int ret;
-
-    fs = filesize(s->pb);
-    atomic_store(&mux->last_filesize, fs);
-    if (fs >= mux->limit_filesize) {
-        ret = AVERROR_EOF;
-        goto fail;
-    }
+    OutputStream *ost = &ms->ost;
 
 #if FFMPEG_OPT_VSYNC_DROP
     if (ost->type == AVMEDIA_TYPE_VIDEO && ost->vsync_method == VSYNC_DROP)
@@ -174,7 +163,7 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
         av_packet_rescale_ts(pkt, pkt->time_base, ost->st->time_base);
     pkt->time_base = ost->st->time_base;
 
-    if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
+    if (!(mux->fc->oformat->flags & AVFMT_NOTIMESTAMPS)) {
         if (pkt->dts != AV_NOPTS_VALUE &&
             pkt->pts != AV_NOPTS_VALUE &&
             pkt->dts > pkt->pts) {
@@ -188,7 +177,7 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
         if ((ost->type == AVMEDIA_TYPE_AUDIO || ost->type == AVMEDIA_TYPE_VIDEO || ost->type == AVMEDIA_TYPE_SUBTITLE) &&
             pkt->dts != AV_NOPTS_VALUE &&
             ms->last_mux_dts != AV_NOPTS_VALUE) {
-            int64_t max = ms->last_mux_dts + !(s->oformat->flags & AVFMT_TS_NONSTRICT);
+            int64_t max = ms->last_mux_dts + !(mux->fc->oformat->flags & AVFMT_TS_NONSTRICT);
             if (pkt->dts < max) {
                 int loglevel = max - pkt->dts > 2 || ost->type == AVMEDIA_TYPE_VIDEO ? AV_LOG_WARNING : AV_LOG_DEBUG;
                 if (exit_on_error)
@@ -197,8 +186,7 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
                        "previous: %"PRId64", current: %"PRId64"; ",
                        ms->last_mux_dts, pkt->dts);
                 if (exit_on_error) {
-                    ret = AVERROR(EINVAL);
-                    goto fail;
+                    return AVERROR(EINVAL);
                 }
 
                 av_log(ost, loglevel, "changing to %"PRId64". This may result "
@@ -212,14 +200,36 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
     }
     ms->last_mux_dts = pkt->dts;
 
+    if (debug_ts)
+        mux_log_debug_ts(ost, pkt);
+
+    return 0;
+}
+
+static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
+{
+    MuxStream *ms = ms_from_ost(ost);
+    AVFormatContext *s = mux->fc;
+    int64_t fs;
+    uint64_t frame_num;
+    int ret;
+
+    fs = filesize(s->pb);
+    atomic_store(&mux->last_filesize, fs);
+    if (fs >= mux->limit_filesize) {
+        ret = AVERROR_EOF;
+        goto fail;
+    }
+
+    ret = mux_fixup_ts(mux, ms, pkt);
+    if (ret < 0)
+        goto fail;
+
     ms->data_size_mux += pkt->size;
     frame_num = atomic_fetch_add(&ost->packets_written, 1);
 
     pkt->stream_index = ost->index;
 
-    if (debug_ts)
-        mux_log_debug_ts(ost, pkt);
-
     if (ms->stats.io)
         enc_stats_write(ost, &ms->stats, NULL, pkt, frame_num);
 



More information about the ffmpeg-cvslog mailing list