summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-05-27 21:56:46 +0200
committerwm4 <wm4@nowhere>2014-06-14 13:50:54 +0200
commitc0f85c18f8ddf4874479ac7fa37e2ac0667e731a (patch)
treeaf909043ff126737e0ac0773b96a77d86fa0af14
parent60111d3f0f96473364367fddc6c546763279e63e (diff)
downloadmpv-c0f85c18f8ddf4874479ac7fa37e2ac0667e731a.tar.bz2
mpv-c0f85c18f8ddf4874479ac7fa37e2ac0667e731a.tar.xz
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.
-rw-r--r--video/decode/dec_video.c10
1 files changed, 9 insertions, 1 deletions
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++;
}