http://blog.grio.com/2012/01/fast-and-slow-motion-video-with-ffmpeg.html
That link points to the right and proper way to do speed ups and slow motion with ffmpeg.
I might actually go a little further and post another explanation of the command.
ffmpeg -i input.mp4 -vf “setpts=(1/X)*PTS” output.mp4
details:
ffmpeg - calls ffmpeg program
-i input.mp4 - file input name of the
-vf - command required for the
"setpts= - command sets the type.
(1/x) - speeds up the video
(x/1) - slows down the video
*PTS" - closes command.
output.mp4 - file name of output video
There are some refinements to this command, though.
You can set the framerate stamped on the output video with
-r to stop ffmpeg dropping frames, with a bit of math.
What good is all this without a few examples.
My GoPro Hero3 will output 240fps in WVGA mode.
To convert that to 25fps slomo, I use the following command:
ffmpeg -i input.mp4 -r 25 -vf "setpts=(9.6/1)*PTS" output.mp4
That's maybe a little extreme... say you want to take some 960p footage down from 100fps to 25fps slowmo:
ffmpeg -i input.mp4 -r 25 -vf "setpts=(4/1)*PTS" output.mp4
Experiment with it a little. I already have two scripts to make conversion easy for the two commonly available GoPro Hero3 output framerates available in Europe. Americans might have to do a little more math to get a clean conversion with no frames dropped or duplicated, as far as slomo goes.
For some reason I am unable to reply to comments. So, in response to the comment below:
Nope, forget completely about duration.
Old fps is 6, new fps is 24. 24/6 = 4, so you want your video to play 4 times as fast.
You would use something like this command:
ffmpeg -i input.mp4 -r 25 -vf "setpts=(1/4)*PTS" output.mp4
Good luck!
P.S. Sorry for the long time to reply. I had to figure out how....
That link points to the right and proper way to do speed ups and slow motion with ffmpeg.
I might actually go a little further and post another explanation of the command.
ffmpeg -i input.mp4 -vf “setpts=(1/X
details:
ffmpeg - calls ffmpeg program
-i input.mp4 - file input name of the
-vf - command required for the
"setpts= - command sets the type.
(1/x) - speeds up the video
(x/1) - slows down the video
*PTS" - closes command.
output.mp4 - file name of output video
There are some refinements to this command, though.
You can set the framerate stamped on the output video with
-r to stop ffmpeg dropping frames, with a bit of math.
What good is all this without a few examples.
My GoPro Hero3 will output 240fps in WVGA mode.
To convert that to 25fps slomo, I use the following command:
ffmpeg -i input.mp4 -r 25 -vf "setpts=(9.6/1)*PTS" output.mp4
That's maybe a little extreme... say you want to take some 960p footage down from 100fps to 25fps slowmo:
ffmpeg -i input.mp4 -r 25 -vf "setpts=(4/1)*PTS" output.mp4
Experiment with it a little. I already have two scripts to make conversion easy for the two commonly available GoPro Hero3 output framerates available in Europe. Americans might have to do a little more math to get a clean conversion with no frames dropped or duplicated, as far as slomo goes.
For some reason I am unable to reply to comments. So, in response to the comment below:
Nope, forget completely about duration.
Old fps is 6, new fps is 24. 24/6 = 4, so you want your video to play 4 times as fast.
You would use something like this command:
ffmpeg -i input.mp4 -r 25 -vf "setpts=(1/4)*PTS" output.mp4
Good luck!
P.S. Sorry for the long time to reply. I had to figure out how....
How does one do math like for the -t duration ?
ReplyDeletelike -t (6*900/24) to get a time duration if the old duration at 6 fps was 900 seconds the new duration at 24 fps would be (6*900/24) is this the right way to do math in ffmpeg ?
Nope, forget completely about duration.
ReplyDeleteOld fps is 6, new fps is 24. 24/6 = 4, so you want your video to play 4 times as fast.
You would use something like this command:
ffmpeg -i input.mp4 -r 25 -vf "setpts=(1/4)*PTS" output.mp4
Good luck!
P.S. Sorry for the long time to reply. I had to figure out how....
In that example, wouldn't it be -r 24? Or am I misunderstanding something...
DeleteYes,it should be -r 24... with "-r 25" you're duplicating frames in the output file.
Deletegreat post thanks! what about audio slowdown to match the video? At the minute, it's sounding as original pitch/speed (so finishes earlier)
ReplyDeleteHow can I guess the duration of the resulting video after slowing down or speeding up video?
ReplyDeleteThis comment has been removed by the author.
ReplyDelete