[FFmpeg-user] Smooth FPS change via ffmpeg

RazrFalcon razrfalcon at gmail.com
Mon Sep 23 19:05:18 EEST 2019


Thanks for a detailed explanation, but I'm still not sure how this should
be implemented.
I understand that I should accumulate/calculate the offset for each PTS,
but I do not understand how.

On Mon, 23 Sep 2019 at 17:06, Nicolas George <george at nsup.org> wrote:

> RazrFalcon (12019-09-23):
> > and it works fine. But when I'm trying to use a "variable" framerate like
> > this:
> >
> > ffmpeg -i raw.mp4 -filter_complex "[v:0]setpts='lerp(2,8,T/5)*PTS'" -r 30
> > out.mp4
> >
> > (5 is a video duration in seconds)
> >
> > the resulting video stutters a lot.
> >
> > Is there are a correct way to smoothly change the framerate using some
> > curve/function?
>
> This is a math issue.
>
> Imagine you want to slow down the second half of a 20 seconds video. The
> formula for the first half is just t' = t. The formula for the second
> half would, naively, be t' = 2*t. But try to plot this, for example in
> gnuplot:
>
> plot [0:20] x < 10 ? x : 2 * x
>
> It does not match at the stitch point. Instead, the second formula needs
> to be t'=2*t-10:
>
> plot [0:20] x < 10 ? x : 2 * x - 10
>
> If we neglect the fact that frames are discrete, we can say that the
> frame rate is the speed of the frames timestamps. In mathematical terms,
> the derivative. The derivative of a linear function is easy. Other kinds
> are more tricky.
>
> If you have a constant frame rate, the timestamps will be affine, but
> you can still choose the constant offset. If you want to connect two
> segments with constant frame rate, you need to adjust the offsets so
> that they match. Hence the -10 in the example.
>
> If the frame rate varies continuously, you need to do the calculus.
> Fortunately, with a linear interpolation, the calculus is easy.
>
> For the same reason:
>
>         sin( (440 + t / 10 * 440) * t)
>
> will NOT give a sine sound going smoothly from 440 Hz to 880 Hz.
>
> Regards,
>
> --
>   Nicolas George
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-user mailing list