From f5219720f8917145cb2e0d9258b3233de1a6fb19 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 27 Nov 2013 20:54:56 +0100 Subject: video: refactor PTS code, add fall back heuristic to DTS Refactor the PTS handling code to make it cleaner, and to separate the bits that use PTS sorting. Add a heuristic to fall back to DTS if the PTS us non-monotonic. This code is based on what FFmpeg/Libav use for ffplay/avplay and also best_effort_timestamp (which is only in FFmpeg). Basically, this 1. just uses the DTS if PTS is unset, and 2. ignores PTS entirely if PTS is non- monotonic, but DTS is sorted. The code is pretty much the same as in Libav [1]. I'm not sure if all of it is really needed, or if it does more than what the paragraph above mentions. But maybe it's fine to cargo-cult this. This heuristic fixes playback of mpeg4 in ogm, which returns packets with PTS==DTS, even though the PTS timestamps should follow codec reordering. This is probably a libavformat demuxer bug, but good luck trying to fix it. The way vd_lavc.c returns the frame PTS and DTS to dec_video.c is a bit inelegant, but maybe better than trying to mess the PTS back into the decoder callback again. [1] https://git.libav.org/?p=libav.git;a=blob;f=cmdutils.c;h=3f1c667075724c5cde69d840ed5ed7d992898334;hb=fa515c2088e1d082d45741bbd5c05e13b0500804#l1431 --- video/decode/vd_lavc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'video/decode/vd_lavc.c') diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c index d29bad6d29..32bbca969f 100644 --- a/video/decode/vd_lavc.c +++ b/video/decode/vd_lavc.c @@ -757,7 +757,7 @@ static int decode(struct dec_video *vd, struct demux_packet *packet, return 0; update_image_params(vd, ctx->pic); - double out_pts = mp_get_av_frame_pkt_pdts(ctx->pic); + mp_get_av_frame_pkt_ts(ctx->pic, &vd->codec_pts, &vd->codec_dts); // Note: potentially resets ctx->pic as it is transferred to mpi struct mp_image *mpi = image_from_decoder(vd); @@ -769,7 +769,6 @@ static int decode(struct dec_video *vd, struct demux_packet *packet, struct mp_image_params vo_params; mp_image_params_from_image(&vo_params, mpi); - mpi->pts = out_pts; if (!mp_image_params_equals(&vo_params, &ctx->vo_image_params)) { mp_image_pool_clear(ctx->non_dr1_pool); -- cgit v1.2.3