From 1b6a191ea3ba4af3c89db98419b5eae899fedcb9 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 3 Feb 2016 21:29:56 +0100 Subject: [PATCH] vd_lavc: force microsecond timestamps on RPI Avoids "problems". In particular, it makes MMAL output a NOPTS timestamp if the input timestamp was NOPTS. Don't do it for other decoders. Ideally, we will at some point in the future switch to integer fractions for timestamps at least up until the filter layer. But this would be a larger change, and for now I'd prefer keeping the not-rounded demuxer timestamps (if we have them). --- video/decode/lavc.h | 1 + video/decode/vd_lavc.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/video/decode/lavc.h b/video/decode/lavc.h index d225195c9d..e9174302b9 100644 --- a/video/decode/lavc.h +++ b/video/decode/lavc.h @@ -17,6 +17,7 @@ typedef struct lavc_ctx { AVCodecContext *avctx; AVFrame *pic; struct vd_lavc_hwdec *hwdec; + AVRational codec_timebase; enum AVPixelFormat pix_fmt; int best_csp; enum AVDiscard skip_frame; diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c index 1e7324457e..64c71afd02 100644 --- a/video/decode/vd_lavc.c +++ b/video/decode/vd_lavc.c @@ -375,6 +375,10 @@ static void init_avctx(struct dec_video *vd, const char *decoder, ctx->hwdec_info = vd->hwdec_info; + ctx->codec_timebase = (AVRational){0}; + if (strstr(decoder, "_mmal")) + ctx->codec_timebase = (AVRational){1, 1000000}; + ctx->pix_fmt = AV_PIX_FMT_NONE; ctx->hwdec = hwdec; ctx->hwdec_fmt = 0; @@ -665,6 +669,7 @@ static void decode(struct dec_video *vd, struct demux_packet *packet, vd_ffmpeg_ctx *ctx = vd->priv; AVCodecContext *avctx = ctx->avctx; struct vd_lavc_params *opts = ctx->opts->vd_lavc_params; + AVRational *tb = ctx->codec_timebase.num ? &ctx->codec_timebase : NULL; AVPacket pkt; if (!avctx) @@ -678,7 +683,7 @@ static void decode(struct dec_video *vd, struct demux_packet *packet, avctx->skip_frame = ctx->skip_frame; } - mp_set_av_packet(&pkt, packet, NULL); + mp_set_av_packet(&pkt, packet, tb); ctx->flushing |= !pkt.data; // Reset decoder if hw state got reset, or new data comes during flushing. @@ -734,8 +739,8 @@ static void decode(struct dec_video *vd, struct demux_packet *packet, return; } assert(mpi->planes[0] || mpi->planes[3]); - mpi->pts = mp_pts_from_av(ctx->pic->pkt_pts, NULL); - mpi->dts = mp_pts_from_av(ctx->pic->pkt_dts, NULL); + mpi->pts = mp_pts_from_av(ctx->pic->pkt_pts, tb); + mpi->dts = mp_pts_from_av(ctx->pic->pkt_dts, tb); struct mp_image_params params; update_image_params(vd, ctx->pic, ¶ms);