ffmpeg: Correct starttime based on non discarded streams.
authorMichael Niedermayer <michaelni@gmx.at>
Sat, 24 Nov 2012 00:34:52 +0000 (01:34 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Sat, 24 Nov 2012 00:54:49 +0000 (01:54 +0100)
Fixes Ticket1830

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
ffmpeg.c

index ad13f18..c10b3c6 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -2775,6 +2775,25 @@ static int process_input(int file_index)
     }
 
     if(!ist->wrap_correction_done && is->start_time != AV_NOPTS_VALUE && ist->st->pts_wrap_bits < 64){
+        // Correcting starttime based on the enabled streams
+        // FIXME this ideally should be done before the first use of starttime but we do not know which are the enabled streams at that point.
+        //       so we instead do it here as part of discontinuity handling
+        if (   ist->next_dts == AV_NOPTS_VALUE
+            && ifile->ts_offset == -is->start_time
+            && (is->iformat->flags & AVFMT_TS_DISCONT)) {
+            int64_t new_start_time = INT64_MAX;
+            for (i=0; i<is->nb_streams; i++) {
+                AVStream *st = is->streams[i];
+                if(st->discard == AVDISCARD_ALL || st->start_time == AV_NOPTS_VALUE)
+                    continue;
+                new_start_time = FFMIN(new_start_time, av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q));
+            }
+            if (new_start_time > is->start_time) {
+                av_log(is, AV_LOG_VERBOSE, "Correcting start time by %"PRId64"\n", new_start_time - is->start_time);
+                ifile->ts_offset = -new_start_time;
+            }
+        }
+
         int64_t stime = av_rescale_q(is->start_time, AV_TIME_BASE_Q, ist->st->time_base);
         int64_t stime2= stime + (1ULL<<ist->st->pts_wrap_bits);
         ist->wrap_correction_done = 1;