[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
Thu May 22 19:14:28 CEST 2014


Please see below the patch for the two remaining points :
1- the duration (take into account the pkt->duration of the last frame)
2- the start_time

For the first one, as you noticed there was previously a DTS order error. After investigation, it appeared that it was related to the retry algorithm : the retry makes the stream to be played in a reverse order, thus the warning. If you disable retry by setting a high value for DURATION_MAX_READ_SIZE, the problem disappeared. Thus, I decided to mask this warning : simply by reset last_dts_for_order_check.
For the second one in "update_initial_timestamps", I have not changed anything since I think you did not highlight any particular issue with it

Nicolas Gaullier
----
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 8e79177..8cd7ea3 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1033,6 +1033,13 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index,
     int64_t shift;
     int i, delay;
 
+    if (pts != AV_NOPTS_VALUE) {
+        if (st->start_time == AV_NOPTS_VALUE) {
+            st->start_time = pts;
+        } else {
+            st->start_time = FFMIN(pts,st->start_time);
+        }
+    }
     if (st->first_dts != AV_NOPTS_VALUE ||
         dts           == AV_NOPTS_VALUE ||
         st->cur_dts   == AV_NOPTS_VALUE ||
@@ -1070,9 +1077,6 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index,
             pktl->pkt.dts = select_from_pts_buffer(st, pts_buffer, pktl->pkt.dts);
         }
     }
-
-    if (st->start_time == AV_NOPTS_VALUE)
-        st->start_time = pts;
 }
 
 static void update_initial_durations(AVFormatContext *s, AVStream *st,
@@ -2507,12 +2511,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