diff options
author | Martin Storsjö <martin@martin.st> | 2012-08-11 21:24:40 +0300 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2012-08-12 12:39:49 +0300 |
commit | bdefe22b8e8c5c1cbcb20595b8eedc052aa8e6e9 (patch) | |
tree | 24c127d52a3ea9c1dc2bb1666423f08b8d93b1ff /libavformat | |
parent | 30c26c2442e4e44ac5a763c23c4b0fdd9921a7f5 (diff) | |
download | ffmpeg-bdefe22b8e8c5c1cbcb20595b8eedc052aa8e6e9.tar.gz |
lavf: Detect discontinuities in timestamps for framerate/analyzeduration calculation
If the dts difference is more than 1000 times the average dts
difference, restart the analysis.
Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/utils.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c index 34177fbdba..8bf688d1cc 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2393,6 +2393,19 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) st->info->fps_last_dts, st->codec_info_nb_frames, pkt->dts); st->info->fps_first_dts = st->info->fps_last_dts = AV_NOPTS_VALUE; } + /* check for a discontinuity in dts - if the difference in dts + * is more than 1000 times the average packet duration in the sequence, + * we treat it as a discontinuity */ + if (st->info->fps_last_dts != AV_NOPTS_VALUE && + st->info->fps_last_dts_idx > st->info->fps_first_dts_idx && + (pkt->dts - st->info->fps_last_dts) / 1000 > + (st->info->fps_last_dts - st->info->fps_first_dts) / (st->info->fps_last_dts_idx - st->info->fps_first_dts_idx)) { + av_log(ic, AV_LOG_WARNING, "DTS discontinuity in stream %d: " + "packet %d with DTS %"PRId64", packet %d with DTS " + "%"PRId64"\n", st->index, st->info->fps_last_dts_idx, + st->info->fps_last_dts, st->codec_info_nb_frames, pkt->dts); + st->info->fps_first_dts = st->info->fps_last_dts = AV_NOPTS_VALUE; + } /* update stored dts values */ if (st->info->fps_first_dts == AV_NOPTS_VALUE) { |