From 3e0dae6959d61c053be9811012debde2f17f8ade Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 20 May 2015 14:24:55 +0200 Subject: video: better heuristic for timestamp resets Reduce the default tolerance for timestamp jumps from 60 to 15 seconds. For .ts files, where ts_resets_possible coming from AVFMT_TS_DISCONT is set, apply a more sophisticated heuristic. It's clear that such a file wouldn't have a framerate below, say, 23hz. If the demuxer reports a lower fps, we allow longer PTS jumps. This should replace long pauses on discontinuities with .ts files with at most a short stutter. Of course, all kinds of things could go wrong anyway if the source is VFR, or FFmpeg's frame rate detection fails in some other way. I haven't found such a file yet, though. --- player/video.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'player') diff --git a/player/video.c b/player/video.c index d35a9de011..4c8af0f46a 100644 --- a/player/video.c +++ b/player/video.c @@ -559,8 +559,19 @@ static void shift_new_frame(struct MPContext *mpctx) double pts = mpctx->next_frame[0]->pts; if (mpctx->video_pts != MP_NOPTS_VALUE) { frame_time = pts - mpctx->video_pts; - if (frame_time <= 0 || frame_time >= 60) { - // Assume a PTS difference >= 60 seconds is a discontinuity. + double tolerance = 15; + if (mpctx->demuxer->ts_resets_possible) { + // Fortunately no real framerate is likely to go below this. It + // still could be that the file is VFR, but the demuxer reports a + // higher rate, so account for the case of e.g. 60hz demuxer fps + // but 23hz actual fps. + double fps = 23.976; + if (mpctx->d_video->fps > 0 && mpctx->d_video->fps < fps) + fps = mpctx->d_video->fps; + tolerance = 3 * 1.0 / fps; + } + if (frame_time <= 0 || frame_time >= tolerance) { + // Assume a discontinuity. MP_WARN(mpctx, "Invalid video timestamp: %f -> %f\n", mpctx->video_pts, pts); frame_time = 0; -- cgit v1.2.3