From c0f85c18f8ddf4874479ac7fa37e2ac0667e731a Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 27 May 2014 21:56:46 +0200 Subject: video: better handling for (very) broken timestamps Sometimes, Matroska files store monotonic PTS for h264 tracks with b-frames, which means the decoder actually returns non-monotonic PTS. Handle this with an evil trick: if DTS is missing, set it to the PTS. Then the existing logic, which deals with falling back to DTS if PTS is broken. Actually, this trick is not so evil at all, because usually, PTS has no errors, and DTS is either always set, or always unset. So this _should_ provoke no regressions (famous last words). libavformat actually does something similar: it derives DTS from PTS in ways unknown to me. The result is very broken, but it causes the DTS fallback to become active, and thus happens to work. Also, prevent the heuristic from being active if PTS is merely monotonic instead of strictly-monotonic. Non-unique PTS is broken, but we can't fallback to DTS anyway in these cases. The specific mkv file that is fixed with this commit had the following fields set: Muxing application: libebml v1.3.0 + libmatroska v1.4.1 Writing application: mkvmerge v6.7.0 ('Back to the Ground') [...] But I know that this should also fix playback of mencoder produced mkv files. --- video/decode/dec_video.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/video/decode/dec_video.c b/video/decode/dec_video.c index 5c75194e75..548a77adf0 100644 --- a/video/decode/dec_video.c +++ b/video/decode/dec_video.c @@ -290,6 +290,14 @@ struct mp_image *video_decode(struct dec_video *d_video, bool sort_pts = (opts->user_pts_assoc_mode != 1 || d_video->header->video->avi_dts) && opts->correct_pts; + + struct demux_packet packet_copy; + if (packet && packet->dts == MP_NOPTS_VALUE) { + packet_copy = *packet; + packet = &packet_copy; + packet->dts = packet->pts; + } + double pkt_pts = packet ? packet->pts : MP_NOPTS_VALUE; double pkt_dts = packet ? packet->dts : MP_NOPTS_VALUE; @@ -323,7 +331,7 @@ struct mp_image *video_decode(struct dec_video *d_video, if (pts == MP_NOPTS_VALUE) { d_video->codec_pts = prev_codec_pts; - } else if (pts <= prev_codec_pts) { + } else if (pts < prev_codec_pts) { d_video->num_codec_pts_problems++; } -- cgit v1.2.3