From 0cbc75c0834a4ba93b67a79467b80324b06165f4 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Sun, 9 Jun 2013 15:37:28 +0200 Subject: Option -omaxfps: limit fps when encoding Lower-fps content is left alone (NOT aligned to this fps); higher fps content is decimated to this frame rate. --- video/out/vo_lavc.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'video') diff --git a/video/out/vo_lavc.c b/video/out/vo_lavc.c index 5140720f92..840103c0c2 100644 --- a/video/out/vo_lavc.c +++ b/video/out/vo_lavc.c @@ -48,6 +48,7 @@ struct priv { double lastpts; int64_t lastipts; int64_t lastframeipts; + int64_t mindeltapts; double expected_next_pts; mp_image_t *lastimg; int lastimg_wants_osd; @@ -317,6 +318,11 @@ static void draw_image(struct vo *vo, mp_image_t *mpi) vc->worst_time_base = vc->stream->time_base; vc->worst_time_base_is_stream = 1; } + if (ectx->options->maxfps) + vc->mindeltapts = ceil(vc->worst_time_base.den / + (vc->worst_time_base.num * ectx->options->maxfps)); + else + vc->mindeltapts = 0; // NOTE: we use the following "axiom" of av_rescale_q: // if time base A is worse than time base B, then @@ -394,6 +400,16 @@ static void draw_image(struct vo *vo, mp_image_t *mpi) vc->lastpts = frameipts * timeunit - encode_lavc_getoffset(ectx, vc->stream); } + // lastipts: pts of last vo frame + // frameipts: pts of current vo frame + // lastframeipts: pts of last ENCODED frame + // now we want to go forward in time until at least lastframeipts + mindeltapts + // so let's just assume this frame took place at this time or later + if (frameipts >= vc->lastframeipts && frameipts < vc->lastframeipts + vc->mindeltapts) { + frameipts = vc->lastframeipts + vc->mindeltapts; + vc->lastpts = frameipts * timeunit - encode_lavc_getoffset(ectx, vc->stream); + } + if (vc->lastipts != MP_NOPTS_VALUE) { frame = avcodec_alloc_frame(); -- cgit v1.2.3