DEV Community

Javid Jamae
Javid Jamae

Posted on • Originally published at ffmpeg-micro.com

How to Speed Up or Slow Down Video with FFmpeg

Originally published at ffmpeg-micro.com.

You need to speed up a video for a timelapse effect or slow it down for dramatic slow motion. FFmpeg handles both with two filters: setpts for video and atempo for audio. But getting them to work together without desyncing audio or producing choppy output trips up most developers.

This guide covers both the raw FFmpeg CLI commands and how to do the same thing with a simple API call through FFmpeg Micro.

How setpts Controls Video Speed

The setpts (set presentation timestamps) filter controls how fast video frames play back. The formula is simple: multiply the PTS value to slow down, divide to speed up.

Double speed (2x faster):

ffmpeg -i input.mp4 -vf "setpts=0.5*PTS" -an output_fast.mp4
Enter fullscreen mode Exit fullscreen mode

The 0.5*PTS halves the timestamp gaps between frames, so they display twice as fast. The -an flag removes audio because audio and video speed need separate handling.

Half speed (2x slower):

ffmpeg -i input.mp4 -vf "setpts=2.0*PTS" -an output_slow.mp4
Enter fullscreen mode Exit fullscreen mode

Doubling the PTS values spaces frames further apart. The video plays at half its original rate.

Custom speeds: multiply PTS by 1/desired_speed. Want 1.5x? Use setpts=0.667*PTS. Want 0.75x? Use setpts=1.333*PTS.

Changing Audio Speed with atempo

Video speed changes do not automatically affect audio. You need the atempo filter for that.

2x audio speed:

ffmpeg -i input.mp4 -af "atempo=2.0" -vn output_audio_fast.mp3
Enter fullscreen mode Exit fullscreen mode

The atempo value directly maps to the speed multiplier. 2.0 means twice as fast.

There is a catch: atempo only accepts values between 0.5 and 2.0. Need 4x speed? Chain two filters together:

ffmpeg -i input.mp4 -af "atempo=2.0,atempo=2.0" -vn output_4x.mp3
Enter fullscreen mode Exit fullscreen mode

Each filter doubles the speed, so two in a row give you 4x. For 0.25x (quarter speed), chain two atempo=0.5 filters.

Speed Up Video and Audio Together

This is where most people get stuck. You need both filters in the same command:

2x speed (video + audio):

ffmpeg -i input.mp4 -vf "setpts=0.5*PTS" -af "atempo=2.0" output_2x.mp4
Enter fullscreen mode Exit fullscreen mode

0.5x slow motion (video + audio):

ffmpeg -i input.mp4 -vf "setpts=2.0*PTS" -af "atempo=0.5" output_half.mp4
Enter fullscreen mode Exit fullscreen mode

3x speed (requires chained atempo):

ffmpeg -i input.mp4 -vf "setpts=0.333*PTS" -af "atempo=2.0,atempo=1.5" output_3x.mp4
Enter fullscreen mode Exit fullscreen mode

The math must line up: setpts gets 1/speed and atempo filters multiply to equal the speed. For 3x, the atempo chain is 2.0 * 1.5 = 3.0.

Using the FFmpeg Micro API for Speed Changes

Instead of managing FFmpeg on your own server, you can send speed change jobs to FFmpeg Micro's API. The options array lets you pass any FFmpeg flag directly.

2x speed via API:

curl -X POST "https://www.ffmpeg-micro.com/v1/transcodes"   -H "Authorization: Bearer YOUR_API_KEY"   -H "Content-Type: application/json"   -d '{"inputs": [{"url": "gs://your-bucket/video.mp4"}], "outputFormat": "mp4", "options": [{"option": "-vf", "argument": "setpts=0.5*PTS"}, {"option": "-af", "argument": "atempo=2.0"}]}'
Enter fullscreen mode Exit fullscreen mode

Upload your file first with the 3-step upload flow, then reference the returned fileUrl in the inputs array. The API handles scaling, encoding, and cleanup.

Common Pitfalls When Changing Video Speed

Audio desync. If you change video speed without matching the audio speed, they will drift apart immediately. Always pair setpts with atempo unless you intentionally want silent output.

atempo range limits. Values outside 0.5 to 2.0 get rejected silently or produce garbage. For 4x, chain atempo=2.0,atempo=2.0. For 0.25x, chain atempo=0.5,atempo=0.5. This is the most common mistake in FFmpeg speed tutorials.

Variable frame rate inputs. Some phone recordings use variable frame rate (VFR). Speed changes on VFR sources produce unpredictable results. Force constant frame rate first with the fps filter before setpts.

No frame interpolation by default. Slowing down a 30fps video to 0.5x gives you 15 unique frames per second (duplicated to fill 30fps). It looks choppy. For smooth slow motion, you need either high-fps source material or the minterpolate filter (which is CPU-intensive).

FAQ

Can I speed up just part of a video with FFmpeg?

Yes. Trim the section you want to speed up with -ss and -t flags, apply the speed change, then concatenate the parts back together.

Does changing video speed affect quality?

Speed changes themselves do not degrade quality. But re-encoding always introduces some generation loss. Use -crf 18 for high quality output.

What is the maximum speed multiplier FFmpeg supports?

There is no hard limit on setpts. You could use setpts=0.01*PTS for 100x speed. The practical limit is atempo for audio (must chain filters for values outside 0.5-2.0 range).

How do I create a timelapse from video with FFmpeg?

Use a high speed multiplier: ffmpeg -i input.mp4 -vf "setpts=0.04*PTS" -an -r 30 timelapse.mp4. This gives you 25x speed. Drop audio with -an since timelapse audio is just noise.

Can FFmpeg Micro handle speed changes in batch?

Yes. Send multiple transcode requests to the /v1/transcodes endpoint. Each job processes independently and scales automatically. No queue management on your end.

Top comments (0)