A fun and easy effect you can add to your videos is to play with the playback speed. You can use this to breathe new life into an existing video – slow it down for some dramatic effect, or speed it up to give it that montage look. Either way you can do this easily with an open-source tool called FFmpeg. In this tutorial we'll walk through how to modify your video's speed with a simple script.
To follow along, make sure you have FFmpeg installed. Instructions for installing FFmpeg are here.
We'll need a few values to start:
- desired speed
- duration of your video
You can get the duration of your video by opening the file in any video preview player or you can use
ffprobe, a tool included in your FFmpeg installation. The following command will tell you the duration of your file:
ffprobe -v quiet -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 your_video_file.mp4
Next you will do a simple calculation for the
-t value (aka time) you'll pass into the next FFmpeg command. We need this value to set the duration of the new video. Without it we may end up with videos that have either too much or too little content, depending on the new speed.
Below is a pseudo-code example
## Slow video down 50% speed=2 video_duration=30 new_video_duration=30 * 2 ## new_video_duration=60
Slow down your video
With your expected video duration in hand, let's build our FFmeg command
ffmpeg -v quiet -i your_video_file -filter:v "setpts=2*PTS" -t 60 your_video_file_2x.mp4
Speed up your video
To create the inverse effect, you can speed up the video 2x
ffmpeg -v quiet -i your_video_file -filter:v "setpts=0.5*PTS" -t 15 your_video_file_0.5x.mp4
-t value was updated to 15 since we are speeding up our video and expect it to be half as long.
Thanks for checking out the tutorial and we hope you found it helpful. If you liked this tutorial, please check out our open-source project: Pluto. It's a command-line tool that let's you do basic media editing just like the above.