[FFmpeg-cvslog] ffmpeg: Correct starttime based on non discarded streams.

Michael Niedermayer git at videolan.org
Sat Nov 24 01:59:59 CET 2012


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sat Nov 24 01:34:52 2012 +0100| [d92073ac9346027de42fda9d934e47f5a2bc97e1] | committer: Michael Niedermayer

ffmpeg: Correct starttime based on non discarded streams.

Fixes Ticket1830

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

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

 ffmpeg.c |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/ffmpeg.c b/ffmpeg.c
index ad13f18..c10b3c6 100644
--- 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;



More information about the ffmpeg-cvslog mailing list