diff options
-rw-r--r-- | mpvcore/player/playloop.c | 1 | ||||
-rw-r--r-- | mpvcore/player/video.c | 63 | ||||
-rw-r--r-- | video/decode/dec_video.c | 3 | ||||
-rw-r--r-- | video/decode/dec_video.h | 1 |
4 files changed, 16 insertions, 52 deletions
diff --git a/mpvcore/player/playloop.c b/mpvcore/player/playloop.c index ad32371699..701443c8cb 100644 --- a/mpvcore/player/playloop.c +++ b/mpvcore/player/playloop.c @@ -176,6 +176,7 @@ static void seek_reset(struct MPContext *mpctx, bool reset_ao) vf_chain_seek_reset(mpctx->d_video->vfilter); mpctx->d_video->num_buffered_pts = 0; mpctx->d_video->last_pts = MP_NOPTS_VALUE; + mpctx->d_video->last_packet_pts = MP_NOPTS_VALUE; mpctx->d_video->pts = MP_NOPTS_VALUE; mpctx->video_pts = MP_NOPTS_VALUE; mpctx->delay = 0; diff --git a/mpvcore/player/video.c b/mpvcore/player/video.c index 362ee94c75..c162cfa51a 100644 --- a/mpvcore/player/video.c +++ b/mpvcore/player/video.c @@ -119,6 +119,7 @@ int reinit_video_chain(struct MPContext *mpctx) struct dec_video *d_video = talloc_zero(NULL, struct dec_video); mpctx->d_video = d_video; d_video->last_pts = MP_NOPTS_VALUE; + d_video->last_packet_pts = MP_NOPTS_VALUE; d_video->opts = mpctx->opts; d_video->header = sh; d_video->fps = sh->video->fps; @@ -266,56 +267,6 @@ static int check_framedrop(struct MPContext *mpctx, double frame_time) return 0; } -static struct demux_packet *video_read_frame(struct MPContext *mpctx) -{ - struct dec_video *d_video = mpctx->d_video; - double frame_time = 1.0f / (d_video->fps > 0 ? d_video->fps : 25); - struct demux_packet *pkt = demux_read_packet(d_video->header); - if (!pkt) - return NULL; // EOF - - if (d_video->last_pts == MP_NOPTS_VALUE) { - d_video->last_pts = pkt->pts == MP_NOPTS_VALUE ? 0 : pkt->pts; - d_video->pts = d_video->last_pts; - } - - double prev = d_video->pts; - d_video->pts = d_video->pts + frame_time; - d_video->last_pts = prev; - return pkt; -} - -static double update_video_nocorrect_pts(struct MPContext *mpctx) -{ - struct dec_video *d_video = mpctx->d_video; - double frame_time = 0; - while (1) { - // In nocorrect-pts mode there is no way to properly time these frames - if (load_next_vo_frame(mpctx, false)) - break; - frame_time = d_video->pts - d_video->last_pts; - if (mpctx->restart_playback) - frame_time = 0; - struct demux_packet *pkt = video_read_frame(mpctx); - if (!pkt) - return -1; - if (mpctx->d_audio) - mpctx->delay -= frame_time; - // video_read_frame can change fps (e.g. for ASF video) - update_fps(mpctx); - int framedrop_type = check_framedrop(mpctx, frame_time); - - pkt->pts = d_video->pts; - void *decoded_frame = video_decode(d_video, pkt, framedrop_type); - talloc_free(pkt); - if (decoded_frame) { - filter_video(mpctx, decoded_frame); - } - break; - } - return frame_time; -} - static double update_video_attached_pic(struct MPContext *mpctx) { struct dec_video *d_video = mpctx->d_video; @@ -338,6 +289,16 @@ static void determine_frame_pts(struct MPContext *mpctx) struct dec_video *d_video = mpctx->d_video; struct MPOpts *opts = mpctx->opts; + if (!opts->correct_pts) { + double frame_time = 1.0f / (d_video->fps > 0 ? d_video->fps : 25); + double pkt_pts = d_video->last_packet_pts; + if (d_video->pts == MP_NOPTS_VALUE) + d_video->pts = pkt_pts == MP_NOPTS_VALUE ? 0 : pkt_pts; + + d_video->pts = d_video->pts + frame_time; + return; + } + if (opts->user_pts_assoc_mode) d_video->pts_assoc_mode = opts->user_pts_assoc_mode; else if (d_video->pts_assoc_mode == 0) { @@ -369,8 +330,6 @@ double update_video(struct MPContext *mpctx, double endpts) struct dec_video *d_video = mpctx->d_video; struct vo *video_out = mpctx->video_out; vf_control(d_video->vfilter, VFCTRL_SET_OSD_OBJ, mpctx->osd); // for vf_sub - if (!mpctx->opts->correct_pts) - return update_video_nocorrect_pts(mpctx); if (d_video->header->attached_picture) return update_video_attached_pic(mpctx); diff --git a/video/decode/dec_video.c b/video/decode/dec_video.c index be2ac8aabe..d2479a7610 100644 --- a/video/decode/dec_video.c +++ b/video/decode/dec_video.c @@ -213,6 +213,9 @@ struct mp_image *video_decode(struct dec_video *d_video, struct MPOpts *opts = d_video->opts; double pts = packet ? packet->pts : MP_NOPTS_VALUE; + if (pts != MP_NOPTS_VALUE) + d_video->last_packet_pts = pts; + if (opts->correct_pts && pts != MP_NOPTS_VALUE) { int delay = -1; video_vd_control(d_video, VDCTRL_QUERY_UNSEEN_FRAMES, &delay); diff --git a/video/decode/dec_video.h b/video/decode/dec_video.h index 3856d12043..827dcb6237 100644 --- a/video/decode/dec_video.h +++ b/video/decode/dec_video.h @@ -58,6 +58,7 @@ struct dec_video { float fps; // FPS from demuxer or from user override float initial_decoder_aspect; + double last_packet_pts; // State used only by player/video.c double last_pts; }; |