lavf/segment: fix DTS inconsistencies with -reset_timestamps

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

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

See thread:
Subject: [FFmpeg-user] pts/dts error using reset_timestamps while splitting a DVD
Date: Sat, 19 Jan 2013 08:58:27 +0000
This commit is contained in:
Stefano Sabatini 2013-02-06 00:19:52 +01:00
parent 59d40fc7e6
commit b3d2c6f8b9

View File

@ -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),