[FFmpeg-user] Smooth FPS change via ffmpeg
Nicolas George
george at nsup.org
Mon Sep 23 17:05:47 EEST 2019
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-user/attachments/20190923/dbfce0de/attachment.sig>
More information about the ffmpeg-user
mailing list