Skip to content

Instantly share code, notes, and snippets.

@hermanschaaf
Last active April 9, 2023 01:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hermanschaaf/2c8dee4b0f6c6d3f74fc17597575d44e to your computer and use it in GitHub Desktop.
Save hermanschaaf/2c8dee4b0f6c6d3f74fc17597575d44e to your computer and use it in GitHub Desktop.
Adjust Speed of a Video with ffmpeg

To increase speed of a video by a factor of 1.5x:

ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=PTS/1.5[v];[0:a]atempo=1.5[a]" -map "[v]" -map "[a]" output.mp4

We can use this to adjust the speed of all the videos in a directory (Linux and macOS only):

mkdir -p output
for i in *.mp4; do ffmpeg -i "$i" -filter_complex "[0:v]setpts=PTS/1.5[v];[0:a]atempo=1.5[a]" -map "[v]" -map "[a]" "output/${i%.*}.mp4"; done

We can also control the size of the resulting videos by using the libx264 codec and the -crf flag. For example:

ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=PTS/1.5[v];[0:a]atempo=1.5[a]" -map "[v]" -map "[a]" -vcodec libx264 -crf 24 output.mp4 

Putting it all together for an entire directory, written to an output directory:

for i in *.mp4; do ffmpeg -i "$i" -filter_complex "[0:v]setpts=PTS/1.5[v];[0:a]atempo=1.5[a]" -map "[v]" -map "[a]" -vcodec libx264 -crf 24 "output/${i%.*}.mp4"; done

Installation Note

If installing ffmpeg from source, in order to use the x264 codec, make sure to specify the following flags when running the configuration step:

./configure --enable-gpl --enable-libx264
@PauloLuan
Copy link

That script saved me a lot of time, tks bro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment