brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ffmpeg setpts=0.25*PTS speeds a video up four times

Ffmpeg
~/tips/tip-ffmpeg-setpts-timelapse

ffmpeg -i build.mp4 -vf "setpts=0.25*PTS" -an build-4x.mp4

Changes the playback speed of the picture, for a timelapse or a slow motion clip.

Every frame in a video carries a timestamp that tells the player when to show it. The setpts filter rewrites those timestamps, and that’s how you change the speed.

ffmpeg -i build.mp4 -vf "setpts=0.25*PTS" -an build-4x.mp4

Multiplying by 0.25 puts the frames closer together, so the video plays four times as fast. A 10-second test clip became 2.56 seconds. For slow motion you go the other way: setpts=2*PTS plays at half speed. Put the expression in quotes so the shell doesn’t treat * as a file pattern; zsh refuses the command without them.

The command has -an because setpts only touches the picture. The audio would keep its normal speed and run out of sync. If you want to keep the sound, speed it up with the atempo filter in the same command: -af atempo=4 together with the 0.25 setpts.

Speeding up keeps all frames, so at four times the speed a 30 fps source plays as 120 frames a second and the file stays big. I’d add -r 30 to drop the extra frames. Slow motion has the opposite problem: it doesn’t invent new frames, so half speed from 30 fps looks choppy.

Further reading: FFmpeg filters documentation

More Ffmpeg tips ffmpeg -stream_loop 2 -i in.mp4 -c copy out.mp4 ffmpeg -i in.mp4 \ ffmpeg -i video.mp4 -i video.en.srt -map 0 -map 1 -c copy -c:s mov_text -metadata:s:s:0 language=eng video-subs.mp4 ffmpeg -i film.mkv -map 0:v -map 0:a:0 -c:v copy -c:a aac -b:a 192k -ac 2 film-stereo.mkv ffmpeg -i talk.mp4 -vn -c:a copy talk.m4a All Ffmpeg tips (38) All topics

Link