This guide will cover how you can use FFmpeg to speed up video and audio, and how to use FFmpeg to slow down videos and audio. You will also learn how to handle the audio and get it in sync with the sped-up or slowed-down video.
FFmpeg is a powerful open-source command-line tool for processing multimedia files. It decodes, encodes, and transcodes. It muxes and demuxes. It streams, filters, and plays almost anything made by humans and machines.
Its versatility makes it popular among developers and video enthusiasts alike. FFmpeg also has another advantage. It works on all major operating systems, such as Windows, Linux, and macOS.
You can download the newest FFmpeg from the official FFmpeg download page.
In this guide, we will use FFmpeg to speed up and slow down the following video:
The first method we will cover is how to use FFmpeg to speed up a video or MP4 file. Then we will cover how to use this same technique to slow down a video. We do this by tweaking the PTS
. The PTS is what informs the media player when to display each video frame or play each audio sample.
The command below will increase the video playback speed by 2x:
ffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" -an output.mp4
Here is a breakdown of the various parameters:
Below is the resulting video from applying the command on the example video. The video is now 13 seconds instead of the original 25 seconds.
You will have noticed that the audio is missing. This requires an additional step which we will cover in the next section.
Run the following command below to slow down a video with FFmpeg. This will make the output video play twice as slow as the input video.
ffmpeg -i input.mp4 -filter:v "setpts=2.0*PTS" -an output.mp4
The difference between this and the previous command is the value of setpts
.
setpts=2.0*PTS
: Doubles the PTS. This means the output video will play at half the speed of the original video.Here is the output video when you apply the command on the example input video. It is now 51 seconds instead of the original 25 seconds.
We’ve covered how to use the -an
flag to disable the audio in the output video. But what if you want to adjust and sync the audio speed too? To do that, you need to use the atempo
audio filter.
The command below will speed up both the video and audio in the output.
ffmpeg -i input.mp4 -vf "setpts=0.5*PTS" -af "atempo=2.0" output.mp4
-af
: This flag applies an audio filter.atempo=2.0
: Doubles the speed of the audio to match the speed of the output video. This will make the audio remain in sync with the video.The following is the result of applying the command on the example video.
You can also slow down the audio to be in sync with a slower output video. Here is an example of a command that does that.
ffmpeg -i input.mp4 -vf "setpts=2.0*PTS" -af "atempo=0.5" output.mp4
Giving atempo
a value of 0.5
will make the audio in the output twice as slow as the original. See the result below.
You can use these commands across different media formats. Below are the FFmpeg commands for working with audio and GIFs. They include speeding up or slowing down audio and making a sped-up or slowed-down GIF.
We will be using the following MP3 file.
To use Ffmpeg to speed up an audio file, use the atempo
filter. The command below speeds up the audio by 2x.
ffmpeg -i input.mp3 -filter:a "atempo=2.0" output.mp3
To use Ffmpeg to slow down an audio file, use the atempo
filter. The command below slows down the audio by 2x:
ffmpeg -i input.mp3 -filter:a "atempo=0.5" output.mp3
We will be using the following GIF.
To use FFmpeg to speed up a GIF, you can adjust the frame rate. The command below speeds up the GIF by increasing the frame rate to twice the original.
ffmpeg -i input.gif -filter:v "setpts=0.5*PTS" output.gif
To slow down a GIF, you can adjust the frame rate. The command below slows down the GIF by decreasing the frame rate to half the original.
ffmpeg -i input.gif -filter:v "setpts=2.0*PTS" output.gif
In this guide, you have learned how to use FFmpeg to speed up an MP4 file. We covered two methods:
PS
) andYou also learned how to handle audio streams when changing the video playback speed, and how to adapt the command to cover audio files and GIFs.
curl --request POST 'https://api.shotstack.io/v1/render' \
--header 'x-api-key: YOUR_API_KEY' \
--data-raw '{
"timeline": {
"tracks": [
{
"clips": [
{
"asset": {
"type": "video",
"src": "https://shotstack-assets.s3.amazonaws.com/footage/beach-overhead.mp4"
},
"start": 0,
"length": "auto"
}
]
}
]
},
"output": {
"format": "mp4",
"size": {
"width": 1280,
"height": 720
}
}
}'