[FFmpeg-devel] [PATCH] MPEG-TS/-PS : better probing for duration and start-time for all streams in a container

Gaullier Nicolas nicolas.gaullier at arkena.com
Mon May 26 16:51:48 CEST 2014


Please see below my new proposal-patch:
The first_dts is the reason why the start_time was stuck to the first packet,
since update_initial_timestamps()  returned immediately without any further processing.
I thus skiped this first_dts test.
I then nearly replaced "x=y" with "x=FFMIN(x,y)" with appropriate checkings.
I think it does not change the structure of the code, so it should be safe.
Thank you,
Nicolas

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 8e79177..81c9975 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1033,14 +1033,15 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index,
     int64_t shift;
     int i, delay;
 
-    if (st->first_dts != AV_NOPTS_VALUE ||
-        dts           == AV_NOPTS_VALUE ||
+    if (dts           == AV_NOPTS_VALUE ||
         st->cur_dts   == AV_NOPTS_VALUE ||
         is_relative(dts))
         return;
 
     delay         = st->codec->has_b_frames;
-    st->first_dts = dts - (st->cur_dts - RELATIVE_TS_BASE);
+    if (st->first_dts == AV_NOPTS_VALUE) {
+           st->first_dts = dts - (st->cur_dts - RELATIVE_TS_BASE);
+    } else st->first_dts = FFMIN(st->first_dts,dts - (st->cur_dts - RELATIVE_TS_BASE));
     st->cur_dts   = dts;
     shift         = st->first_dts - RELATIVE_TS_BASE;
 
@@ -1059,8 +1060,11 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index,
         if (is_relative(pktl->pkt.dts))
             pktl->pkt.dts += shift;
 
-        if (st->start_time == AV_NOPTS_VALUE && pktl->pkt.pts != AV_NOPTS_VALUE)
-            st->start_time = pktl->pkt.pts;
+        if (pktl->pkt.pts != AV_NOPTS_VALUE) {
+            if (st->start_time == AV_NOPTS_VALUE) {
+                   st->start_time = pktl->pkt.pts;
+            } else st->start_time = FFMIN(st->start_time, pktl->pkt.pts);
+        }
 
         if (pktl->pkt.pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY && has_decode_delay_been_guessed(st)) {
             pts_buffer[0] = pktl->pkt.pts;
@@ -1071,8 +1075,11 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index,
         }
     }
 
-    if (st->start_time == AV_NOPTS_VALUE)
-        st->start_time = pts;
+    if (pts != AV_NOPTS_VALUE) {
+        if (st->start_time == AV_NOPTS_VALUE) {
+               st->start_time = pts;
+        } else st->start_time = FFMIN(st->start_time, pts);
+    }
 }
 
 static void update_initial_durations(AVFormatContext *s, AVStream *st,
@@ -2507,12 +2514,13 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
 
         avio_seek(ic->pb, offset, SEEK_SET);
         read_size = 0;
+        st->last_dts_for_order_check=0;
         for (;;) {
             if (read_size >= DURATION_MAX_READ_SIZE << (FFMAX(retry - 1, 0)))
                 break;
 
             do {
-                ret = ff_read_packet(ic, pkt);
+                ret = read_frame_internal(ic,pkt);
             } while (ret == AVERROR(EAGAIN));
             if (ret != 0)
                 break;




More information about the ffmpeg-devel mailing list