Change video speed with FFmpeg

Divide the timestamps with setpts to change the picture speed, and set atempo to the same factor so the sound keeps up. setpts=PTS/2 with atempo=2 doubles the speed, setpts=2*PTS with atempo=0.5 halves it. Every command below ran on the same 20-second clip.

Faster Re-encode

Speed up picture and sound together. The voice keeps its pitch.

ffmpeg -i in.mp4 -vf setpts=PTS/2 -af atempo=2 out.mp4

10.08 s with sound. 242 frames at 24 fps: FFmpeg dropped every other frame to keep the frame rate.

Length
20 s in, 10.08 s out
Frames
480 in, 242 out
Run time
1.2 s
Output
3.2 MB
Slower Re-encode

Slow down picture and sound together. No frames are invented.

ffmpeg -i in.mp4 -vf setpts=2*PTS -af atempo=0.5 out.mp4

40.01 s with sound. All 480 frames, each held twice as long, so the file is 12 fps.

Length
20 s in, 40.01 s out
Frame rate
24 in, 12 out
Run time
2.1 s
Output
7.0 MB

Proof

The same sound at three speeds

Each waveform is drawn on the same 40-second scale, so its width is its length. Below them, three frames in a row from each way of filling slow motion.
in.mp4
Waveform of the original 20-second clip, filling half of a 40-second scale
20.00 s The original sound track.
setpts=PTS/2, atempo=2 Same shape, half the length
Waveform after setpts=PTS/2 and atempo=2, the same shape squeezed into a quarter of the scale
10.01 s atempo shortens the sound without raising its pitch. On a 440 Hz test tone, atempo=2 halved the length and the tone stayed at 440 Hz. Raising the sample rate instead (asetrate) put it at 880 Hz.
setpts=2*PTS, atempo=0.5 Same shape, twice the length
Waveform after setpts=2*PTS and atempo=0.5, the same shape stretched across the whole scale
40.01 s The sound track of the half-speed answer, stretched to match the picture.
setpts=2*PTS, -r 24 Every frame shown twice
Three neighbouring frames of the half-speed clip with -r 24: the first two are the same picture
959 frames Frames 49, 50 and 51. Asking for 24 fps fills the gaps with copies: 49 and 50 are the same picture, then the hand jumps.
minterpolate=fps=48, setpts=2*PTS A new picture every frame
Three neighbouring frames of the minterpolate slow motion clip, each a new in-between picture
24 fps The same three frame numbers. minterpolate drew a new picture between each pair of real ones, so the hand moves on every frame.

Footage: Sintel, © Blender Foundation, CC BY 3.0.

Run it

Run it on Rendobar

Send the same command from your code. The job fetches each input from its URL and returns the output file's URL when it finishes.

job.ts
import { createClient } from "@rendobar/sdk";
const rb = createClient({ apiKey: process.env.RENDOBAR_API_KEY });
const job = await rb.jobs.run({
type: "ffmpeg",
inputs: {
"in.mp4": "https://cdn.rendobar.com/examples/change-video-speed/in.mp4",
},
params: {
command: "ffmpeg -i in.mp4 -vf setpts=PTS/2 -af atempo=2 out.mp4",
},
});
console.log(job.output.file.url);

Install with npm i @rendobar/sdk. jobs.run() submits and waits, so it returns the finished job in one call.

terminal
curl https://api.rendobar.com/jobs \
-H "Authorization: Bearer $RENDOBAR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "ffmpeg",
"inputs": {
"in.mp4": "https://cdn.rendobar.com/examples/change-video-speed/in.mp4"
},
"params": {
"command": "ffmpeg -i in.mp4 -vf setpts=PTS/2 -af atempo=2 out.mp4"
}
}'

Returns immediately with a job id. Poll GET /jobs/{id} or register a webhook rather than blocking on the request.

Every variant

Pick the command for your case

Each one ran on the same input. The line under it is what came out. Run times are the best of three runs with FFmpeg 8.0 on one desktop machine, so read them as relative.

  1. Speed up by 1.5x

    Re-encode
    ffmpeg -i in.mp4 -vf setpts=PTS/1.5 -af atempo=1.5 out.mp4

    13.38 s, 321 frames at 24 fps. Any factor works the same way: divide in setpts, multiply in atempo.

    1.5 s run 3.9 MB 13.38 s long

  2. Speed up by 4x

    Re-encode
    ffmpeg -i in.mp4 -vf setpts=PTS/4 -af atempo=4 out.mp4

    5.08 s of picture, 4.99 s of sound, from one atempo. No chaining needed on FFmpeg 8.0.

    855 ms run 2.1 MB 5.08 s long

  3. Slow down to quarter speed

    Re-encode
    ffmpeg -i in.mp4 -vf setpts=4*PTS -af atempo=0.5,atempo=0.5 out.mp4

    79.99 s at 6 fps. atempo stops at 0.5, so two of them in a row make 0.25.

    2.5 s run 9.4 MB 79.99 s long

  4. Make a 10x timelapse with no sound

    Re-encode
    ffmpeg -i in.mp4 -vf setpts=PTS/10 -an out.mp4

    2.08 s, 50 frames. FFmpeg kept 1 frame in 10 to stay at 24 fps. -an drops the sound.

    555 ms run 1.2 MB 2.08 s long

  5. Speed up the picture and remove the sound

    Re-encode
    ffmpeg -i in.mp4 -vf setpts=PTS/2 -an out.mp4

    10.08 s, video only. Without -an the sound stays at full length: see the first question below.

    1.2 s run 3.1 MB 10.08 s long

  6. Make smooth slow motion with new frames

    Re-encode
    ffmpeg -t 5 -i in.mp4 -vf "minterpolate=fps=48,setpts=2*PTS" -af atempo=0.5 out.mp4

    The first 5 s become 9.97 s at 24 fps, every frame a new picture. minterpolate estimates motion for every pixel, so try it on a short clip first.

    12.7 s run 1.4 MB 9.97 s long

  7. Change speed without re-encoding

    Stream copy
    ffmpeg -itsscale 0.5 -i in.mp4 -an -c copy out.mp4

    10.02 s at 48 fps, all 480 frames copied untouched. Only the timestamps changed. The sound has to go.

    78 ms run 7.1 MB 10.02 s long

  8. Speed up one part of a video

    Re-encode
    ffmpeg -i in.mp4 -filter_complex "[0:v]trim=0:5,setpts=PTS-STARTPTS[v0];[0:a]atrim=0:5,asetpts=PTS-STARTPTS[a0];[0:v]trim=5:15,setpts=(PTS-STARTPTS)/2[v1];[0:a]atrim=5:15,asetpts=PTS-STARTPTS,atempo=2[a1];[0:v]trim=15,setpts=PTS-STARTPTS[v2];[0:a]atrim=15,asetpts=PTS-STARTPTS[a2];[v0][a0][v1][a1][v2][a2]concat=n=3:v=1:a=1[v][a]" -map "[v]" -map "[a]" out.mp4

    0:00 to 0:05 at normal speed, 0:05 to 0:15 at 2x, the rest normal: 15.04 s in one pass, no temporary files.

    1.6 s run 4.3 MB 15.04 s long

Gotchas

Where it goes wrong

Why is my sped-up video still the same length?

setpts only changes the picture. The sound keeps its own timing unless you change it too:

ffmpeg -i in.mp4 -vf setpts=PTS/2 out.mp4

The video stream ends at 10.08 s, the audio at 20.01 s, and the file is 20.01 s long. Players hold the last frame for the second half while the sound plays at normal speed.

Add -af atempo=2 to speed the sound up with it, or -an to drop it.

Is atempo limited to 0.5 to 2.0?

Not on current builds. FFmpeg 8.0 accepts 0.5 to 100 in one atempo, and atempo=4 gave 4.99 s of sound from 20 s. Older answers chain atempo=2,atempo=2 for 4x, which still works.

Slower than 0.5 is still out of range:

ffmpeg -i in.mp4 -vf setpts=4*PTS -af atempo=0.25 out.mp4

Fails before writing anything: Value 0.250000 for parameter 'tempo' out of range [0.5 - 100].

Chain two filters whose product is the factor you want: atempo=0.5,atempo=0.5 for 0.25.

Why does my slow motion look choppy?

Half speed has half as many pictures per second. setpts=2*PTS keeps all 480 frames and writes a 12 fps file. Adding -r 24 does not add motion:

ffmpeg -i in.mp4 -vf setpts=2*PTS -af atempo=0.5 -r 24 out.mp4

959 frames at 24 fps, and every other frame is a copy of the one before. The luma difference between neighbours alternated between about 3.2 and 0.04.

For new in-between pictures, interpolate first and slow down second, as in the smooth slow motion task above. Each frame then differed from the last by about 1.8, half a real step. It estimates motion for every pixel, which is why the task above runs it on the first 5 s only.

Can I change the speed without re-encoding?

For the picture, yes. -itsscale before -i multiplies the input timestamps, and -c copy keeps every frame as it was:

ffmpeg -itsscale 0.5 -i in.mp4 -an -c copy out.mp4

10.02 s, 48 fps, 480 frames, the video bytes untouched.

The sound cannot follow. A copied AAC stream plays at the speed it was encoded at, so drop it with -an, or re-encode the audio with atempo in a second step.

Related: Change frame rate, Trim a video, Loop a video, MP4 to GIF.

Your command. Our infrastructure.

Bring your own commands. Run them on scalable CPU and GPU infrastructure, and pay only for compute time.