double update_video(struct MPContext *mpctx, double endpts) { struct sh_video *sh_video = mpctx->sh_video; struct vo *video_out = mpctx->video_out; sh_video->vfilter->control(sh_video->vfilter, VFCTRL_SET_OSD_OBJ, mpctx->osd); // for vf_sub if (!mpctx->opts->correct_pts) return update_video_nocorrect_pts(mpctx); if (sh_video->gsh->attached_picture) return update_video_attached_pic(mpctx); double pts; while (1) { if (load_next_vo_frame(mpctx, false)) break; pts = MP_NOPTS_VALUE; struct demux_packet *pkt = NULL; while (1) { pkt = demux_read_packet(mpctx->sh_video->gsh); if (!pkt || pkt->len) break; /* Packets with size 0 are assumed to not correspond to frames, * but to indicate the absence of a frame in formats like AVI * that must have packets at fixed timecode intervals. */ talloc_free(pkt); } if (pkt) pts = pkt->pts; if (pts != MP_NOPTS_VALUE) pts += mpctx->video_offset; if (pts >= mpctx->hrseek_pts - .005) mpctx->hrseek_framedrop = false; int framedrop_type = mpctx->hrseek_active && mpctx->hrseek_framedrop ? 1 : check_framedrop(mpctx, -1); struct mp_image *decoded_frame = decode_video(sh_video, pkt, framedrop_type, pts); talloc_free(pkt); if (decoded_frame) { determine_frame_pts(mpctx); filter_video(mpctx, decoded_frame); } else if (!pkt) { if (!load_next_vo_frame(mpctx, true)) return -1; } break; } if (!video_out->frame_loaded) return 0; pts = video_out->next_pts; if (pts == MP_NOPTS_VALUE) { MP_ERR(mpctx, "Video pts after filters MISSING\n"); // Try to use decoder pts from before filters pts = sh_video->pts; if (pts == MP_NOPTS_VALUE) pts = sh_video->last_pts; } if (endpts == MP_NOPTS_VALUE || pts < endpts) add_frame_pts(mpctx, pts); if (mpctx->hrseek_active && pts < mpctx->hrseek_pts - .005) { vo_skip_frame(video_out); return 0; } mpctx->hrseek_active = false; sh_video->pts = pts; if (sh_video->last_pts == MP_NOPTS_VALUE) sh_video->last_pts = sh_video->pts; else if (sh_video->last_pts > sh_video->pts) { MP_WARN(mpctx, "Decreasing video pts: %f < %f\n", sh_video->pts, sh_video->last_pts); /* If the difference in pts is small treat it as jitter around the * right value (possibly caused by incorrect timestamp ordering) and * just show this frame immediately after the last one. * Treat bigger differences as timestamp resets and start counting * timing of later frames from the position of this one. */ if (sh_video->last_pts - sh_video->pts > 0.5) sh_video->last_pts = sh_video->pts; else sh_video->pts = sh_video->last_pts; } else if (sh_video->pts >= sh_video->last_pts + 60) { // Assume a PTS difference >= 60 seconds is a discontinuity. MP_WARN(mpctx, "Jump in video pts: %f -> %f\n", sh_video->last_pts, sh_video->pts); sh_video->last_pts = sh_video->pts; } double frame_time = sh_video->pts - sh_video->last_pts; sh_video->last_pts = sh_video->pts; if (mpctx->sh_audio) mpctx->delay -= frame_time; return frame_time; }
double update_video(struct MPContext *mpctx, double endpts) { struct dec_video *d_video = mpctx->d_video; struct vo *video_out = mpctx->video_out; if (d_video->header->attached_picture) return update_video_attached_pic(mpctx); if (load_next_vo_frame(mpctx, false)) { // Use currently queued VO frame } else if (d_video->waiting_decoded_mpi) { // Draining on reconfig if (!load_next_vo_frame(mpctx, true)) return -1; } else { // Decode a new frame struct demux_packet *pkt = demux_read_packet(d_video->header); if (pkt && pkt->pts != MP_NOPTS_VALUE) pkt->pts += mpctx->video_offset; if ((pkt && pkt->pts >= mpctx->hrseek_pts - .005) || d_video->has_broken_packet_pts) { mpctx->hrseek_framedrop = false; } int framedrop_type = mpctx->hrseek_active && mpctx->hrseek_framedrop ? 1 : check_framedrop(mpctx, -1); struct mp_image *decoded_frame = video_decode(d_video, pkt, framedrop_type); talloc_free(pkt); if (decoded_frame) { filter_video(mpctx, decoded_frame, false); } else if (!pkt) { if (!load_next_vo_frame(mpctx, true)) return -1; } } // Whether the VO has an image queued. // If it does, it will be used to time and display the next frame. if (!video_out->frame_loaded) return 0; double pts = video_out->next_pts; if (endpts == MP_NOPTS_VALUE || pts < endpts) add_frame_pts(mpctx, pts); if (mpctx->hrseek_active && pts < mpctx->hrseek_pts - .005) { vo_skip_frame(video_out); return 0; } mpctx->hrseek_active = false; double last_pts = mpctx->video_next_pts; if (last_pts == MP_NOPTS_VALUE) last_pts = pts; double frame_time = pts - last_pts; if (frame_time < 0 || frame_time >= 60) { // Assume a PTS difference >= 60 seconds is a discontinuity. MP_WARN(mpctx, "Jump in video pts: %f -> %f\n", last_pts, pts); frame_time = 0; } mpctx->video_next_pts = pts; if (mpctx->d_audio) mpctx->delay -= frame_time; return frame_time; }