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.

About FFmpeg

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:

Change playback speed by adjusting the presentation timestamp (PTS)

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.

Speed up the video using the PTS

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:

  • -i input.mp4: Specifies the input video file that FFmpeg will process. Replace input.mp4 with the name of your video file.
  • -filter:v: Applies a video filter to the input video stream.
  • setpts=0.5PTS: It reduces the PTS by half (0.5), which makes the output video play twice as fast as the original video. You can adjust the figure to suit your use case. For example, using 0.25PTS will make the output video play four times faster.
  • -an: The -an stands for “audio none” and it disables the audio stream in the output file.

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.

Use FFmpeg to slow down a video 2x

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.

Handling audio when adjusting video playback speed

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.

Speeding up both video and audio

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.

Slowing down both video and audio

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.

Speeding Up and Slowing Down Audio

We will be using the following MP3 file.

Use FFmpeg to speed up audio

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

Use FFmpeg to slow down audio

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

Speeding Up and Slowing Down GIFs

We will be using the following GIF.

Happy Birthday GIF

Use FFmpeg to speed up a 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

Happy Birthday GIF fast

Use FFmpeg to slow down a 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

Happy Birthday GIF slow

Conclusion

In this guide, you have learned how to use FFmpeg to speed up an MP4 file. We covered two methods:

  1. Adjusting the presentation timestamp (PS) and
  2. Changing the frame rate.

You 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.

Get started with Shotstack's video editing API in two steps:

  1. Sign up for free to get your API key.
  2. Send an API request to create your video:
    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
    }
    }
    }'
Benjamin Semah

BY BENJAMIN SEMAH
10th July 2024

Studio Real Estate
Experience Shotstack for yourself.
SIGN UP FOR FREE

You might also like

Generate audio waveform videos using FFmpeg

Generate audio waveform videos using FFmpeg

Jeff Shillitto
Use FFmpeg to extract frames from video

Use FFmpeg to extract frames from video

Peace Aisosa
How to compress video using FFmpeg

How to compress video using FFmpeg

Maab Saleem