[FFmpeg-cvslog] fftools/ffmpeg: move inter-stream ts discontinuity handling to ts_discontinuity_process()

Anton Khirnov git at videolan.org
Sat Aug 13 15:01:36 EEST 2022


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed Aug 10 16:48:03 2022 +0200| [aa6d4a53e3c0e792b14d3b27357faade6940b10a] | committer: Anton Khirnov

fftools/ffmpeg: move inter-stream ts discontinuity handling to ts_discontinuity_process()

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

 fftools/ffmpeg.c | 37 +++++++++++++++----------------------
 1 file changed, 15 insertions(+), 22 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 1cbd78429a..e76863b91d 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3744,7 +3744,22 @@ static void ts_discontinuity_process(InputFile *ifile, InputStream *ist,
                 }
             }
         }
+    } else if (ist->next_dts == AV_NOPTS_VALUE && !copy_ts &&
+               fmt_is_discont && ifile->last_ts != AV_NOPTS_VALUE) {
+        int64_t delta = pkt_dts - ifile->last_ts;
+        if (delta < -1LL*dts_delta_threshold*AV_TIME_BASE ||
+            delta >  1LL*dts_delta_threshold*AV_TIME_BASE) {
+            ifile->ts_offset -= delta;
+            av_log(NULL, AV_LOG_DEBUG,
+                   "Inter stream timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
+                   delta, ifile->ts_offset);
+            pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
+            if (pkt->pts != AV_NOPTS_VALUE)
+                pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
+        }
     }
+
+    ifile->last_ts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
 }
 
 /*
@@ -3762,7 +3777,6 @@ static int process_input(int file_index)
     AVPacket *pkt;
     int ret, i, j;
     int64_t duration;
-    int64_t pkt_dts;
 
     is  = ifile->ctx;
     ret = ifile_get_packet(ifile, &pkt);
@@ -3878,24 +3892,6 @@ static int process_input(int file_index)
     if (pkt->dts != AV_NOPTS_VALUE)
         pkt->dts *= ist->ts_scale;
 
-    pkt_dts = av_rescale_q_rnd(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
-    if ((ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
-         ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) &&
-        pkt_dts != AV_NOPTS_VALUE && ist->next_dts == AV_NOPTS_VALUE && !copy_ts
-        && (is->iformat->flags & AVFMT_TS_DISCONT) && ifile->last_ts != AV_NOPTS_VALUE) {
-        int64_t delta   = pkt_dts - ifile->last_ts;
-        if (delta < -1LL*dts_delta_threshold*AV_TIME_BASE ||
-            delta >  1LL*dts_delta_threshold*AV_TIME_BASE){
-            ifile->ts_offset -= delta;
-            av_log(NULL, AV_LOG_DEBUG,
-                   "Inter stream timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
-                   delta, ifile->ts_offset);
-            pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
-            if (pkt->pts != AV_NOPTS_VALUE)
-                pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
-        }
-    }
-
     duration = av_rescale_q(ifile->duration, ifile->time_base, ist->st->time_base);
     if (pkt->pts != AV_NOPTS_VALUE) {
         pkt->pts += duration;
@@ -3912,9 +3908,6 @@ static int process_input(int file_index)
         pkt->dts != AV_NOPTS_VALUE)
         ts_discontinuity_process(ifile, ist, pkt);
 
-    if (pkt->dts != AV_NOPTS_VALUE)
-        ifile->last_ts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
-
     if (debug_ts) {
         av_log(NULL, AV_LOG_INFO, "demuxer+ffmpeg -> ist_index:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n",
                ifile->ist_index + pkt->stream_index,



More information about the ffmpeg-cvslog mailing list