diff options
author | wm4 <wm4@nowhere> | 2015-10-06 18:13:23 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-10-06 18:19:20 +0200 |
commit | b4804a4b2614bca5c33e65a399e98669ece72a01 (patch) | |
tree | 9f3f60c22eb88d76867c1e929d21588193502ffc | |
parent | 5015759334214da4a85fafd54e67319e380e25bd (diff) | |
download | mpv-b4804a4b2614bca5c33e65a399e98669ece72a01.tar.bz2 mpv-b4804a4b2614bca5c33e65a399e98669ece72a01.tar.xz |
video: fix base for --no-correct-pts
Use the first encountered packet PTS/DTS as base, instead of the last
one. This does not add the amount of frames buffered in the codec to the
PTS offset, and thus is better.
Also, don't add the frame time if there was no decoded frame yet. The
first frame should obviously have the timestamp of the first packet
(going by this heuristic).
-rw-r--r-- | video/decode/dec_video.c | 15 | ||||
-rw-r--r-- | video/decode/dec_video.h | 4 |
2 files changed, 10 insertions, 9 deletions
diff --git a/video/decode/dec_video.c b/video/decode/dec_video.c index b0bdee3202..af55c66811 100644 --- a/video/decode/dec_video.c +++ b/video/decode/dec_video.c @@ -63,7 +63,7 @@ void video_reset_decoding(struct dec_video *d_video) mp_image_unrefp(&d_video->waiting_decoded_mpi); d_video->num_buffered_pts = 0; d_video->last_pts = MP_NOPTS_VALUE; - d_video->last_packet_pdts = MP_NOPTS_VALUE; + d_video->first_packet_pdts = MP_NOPTS_VALUE; d_video->decoded_pts = MP_NOPTS_VALUE; d_video->codec_pts = MP_NOPTS_VALUE; d_video->codec_dts = MP_NOPTS_VALUE; @@ -250,8 +250,8 @@ struct mp_image *video_decode(struct dec_video *d_video, double pkt_dts = packet ? packet->dts : MP_NOPTS_VALUE; double pkt_pdts = pkt_pts == MP_NOPTS_VALUE ? pkt_dts : pkt_pts; - if (pkt_pdts != MP_NOPTS_VALUE) - d_video->last_packet_pdts = pkt_pdts; + if (pkt_pdts != MP_NOPTS_VALUE && d_video->first_packet_pdts == MP_NOPTS_VALUE) + d_video->first_packet_pdts = pkt_pdts; if (avi_pts) add_avi_pts(d_video, pkt_pdts); @@ -310,12 +310,13 @@ struct mp_image *video_decode(struct dec_video *d_video, MP_WARN(d_video, "No video PTS! Making something up.\n"); double frame_time = 1.0f / (d_video->fps > 0 ? d_video->fps : 25); - double base = d_video->last_packet_pdts; + double base = d_video->first_packet_pdts; pts = d_video->decoded_pts; - if (pts == MP_NOPTS_VALUE) + if (pts == MP_NOPTS_VALUE) { pts = base == MP_NOPTS_VALUE ? 0 : base; - - pts += frame_time; + } else { + pts += frame_time; + } } if (d_video->has_broken_packet_pts < 0) diff --git a/video/decode/dec_video.h b/video/decode/dec_video.h index 2edf8b67c4..28844f5882 100644 --- a/video/decode/dec_video.h +++ b/video/decode/dec_video.h @@ -59,8 +59,8 @@ struct dec_video { double buffered_pts[64]; int num_buffered_pts; - // PTS or DTS of packet last read - double last_packet_pdts; + // PTS or DTS of packet first read + double first_packet_pdts; // There was at least one packet with non-sense timestamps. int has_broken_packet_pts; // <0: uninitialized, 0: no problems, 1: broken |