[FFmpeg-devel] [PATCH] lavf/segment: fix DTS inconsistencies with -reset_timestamps

Stefano Sabatini stefasab at gmail.com
Wed Feb 6 00:48:44 CET 2013


The DTS needs to be resynched against the start_pts, or the resulting DTS
may result < PTS.

Reported-by: Owen Jones <riots6 at gmail.com>

See:
Subject: [FFmpeg-user] pts/dts error using reset_timestamps while splitting a DVD
Date: Sat, 19 Jan 2013 08:58:27 +0000
---
 libavformat/segment.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/libavformat/segment.c b/libavformat/segment.c
index 4ae2019..13d8c43 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -42,7 +42,7 @@
 typedef struct SegmentListEntry {
     int index;
     double start_time, end_time;
-    int64_t start_pts, start_dts;
+    int64_t start_pts;
     char filename[1024];
     struct SegmentListEntry *next;
 } SegmentListEntry;
@@ -664,8 +664,6 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
         seg->cur_entry.index = seg->segment_idx;
         seg->cur_entry.start_time = (double)pkt->pts * av_q2d(st->time_base);
         seg->cur_entry.start_pts = av_rescale_q(pkt->pts, st->time_base, AV_TIME_BASE_Q);
-        seg->cur_entry.start_dts = pkt->dts != AV_NOPTS_VALUE ?
-            av_rescale_q(pkt->dts, st->time_base, AV_TIME_BASE_Q) : seg->cur_entry.start_pts;
     } else if (pkt->pts != AV_NOPTS_VALUE) {
         seg->cur_entry.end_time =
             FFMAX(seg->cur_entry.end_time, (double)(pkt->pts + pkt->duration) * av_q2d(st->time_base));
@@ -679,18 +677,17 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
     }
 
     if (seg->reset_timestamps) {
-        av_log(s, AV_LOG_DEBUG, "stream:%d start_pts_time:%s pts:%s pts_time:%s start_dts_time:%s dts:%s dts_time:%s",
+        av_log(s, AV_LOG_DEBUG, "stream:%d start_pts_time:%s pts:%s pts_time:%s dts:%s dts_time:%s",
                pkt->stream_index,
                av_ts2timestr(seg->cur_entry.start_pts, &AV_TIME_BASE_Q),
                av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
-               av_ts2timestr(seg->cur_entry.start_dts, &AV_TIME_BASE_Q),
                av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
 
         /* compute new timestamps */
         if (pkt->pts != AV_NOPTS_VALUE)
             pkt->pts -= av_rescale_q(seg->cur_entry.start_pts, AV_TIME_BASE_Q, st->time_base);
         if (pkt->dts != AV_NOPTS_VALUE)
-            pkt->dts -= av_rescale_q(seg->cur_entry.start_dts, AV_TIME_BASE_Q, st->time_base);
+            pkt->dts -= av_rescale_q(seg->cur_entry.start_pts, AV_TIME_BASE_Q, st->time_base);
 
         av_log(s, AV_LOG_DEBUG, " -> pts:%s pts_time:%s dts:%s dts_time:%s\n",
                av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list