mirror of
https://github.com/mpv-player/mpv
synced 2024-12-24 07:42:17 +00:00
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).
This commit is contained in:
parent
5015759334
commit
b4804a4b26
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user