Skip to content

Instantly share code, notes, and snippets.

@limkokhole
Forked from hermanschaaf/adjust_video_speed.md
Created January 18, 2020 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save limkokhole/059ffa619e58f6cb9910ed995c1a0361 to your computer and use it in GitHub Desktop.
Save limkokhole/059ffa619e58f6cb9910ed995c1a0361 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment