mirror of https://github.com/mpv-player/mpv
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.
This commit is contained in:
parent
96bc188172
commit
22b16a40e5
|
@ -290,6 +290,14 @@ struct mp_image *video_decode(struct dec_video *d_video,
|
||||||
bool sort_pts =
|
bool sort_pts =
|
||||||
(opts->user_pts_assoc_mode != 1 || d_video->header->video->avi_dts)
|
(opts->user_pts_assoc_mode != 1 || d_video->header->video->avi_dts)
|
||||||
&& opts->correct_pts;
|
&& 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_pts = packet ? packet->pts : MP_NOPTS_VALUE;
|
||||||
double pkt_dts = packet ? packet->dts : MP_NOPTS_VALUE;
|
double pkt_dts = packet ? packet->dts : MP_NOPTS_VALUE;
|
||||||
|
|
||||||
|
@ -325,7 +333,7 @@ struct mp_image *video_decode(struct dec_video *d_video,
|
||||||
|
|
||||||
if (pts == MP_NOPTS_VALUE) {
|
if (pts == MP_NOPTS_VALUE) {
|
||||||
d_video->codec_pts = prev_codec_pts;
|
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++;
|
d_video->num_codec_pts_problems++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue