Skip to content

Instantly share code, notes, and snippets.

@PauloLuan
Last active February 25, 2023 22:54
Show Gist options
  • Save PauloLuan/18d0babd1f29db8d33cbc71e203de91e to your computer and use it in GitHub Desktop.
Save PauloLuan/18d0babd1f29db8d33cbc71e203de91e to your computer and use it in GitHub Desktop.
ffmpeg 1.5x

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
Author

IGTV 1.5x:

ffmpeg -i 2020-03-06_12-03-15.mp4 -filter_complex "[0:v]setpts=PTS/1.5[v];[0:a]atempo=1.5[a]" -map "[v]" -map "[a]" -aspect 9:16 -s 1080x1920 output.mp4

@PauloLuan
Copy link
Author

Feed:

ffmpeg -i 2020-03-06_12-03-15.mp4 -filter_complex "[0:v]setpts=PTS/1.5[v];[0:a]atempo=1.5[a]" -map "[v]" -map "[a]" -aspect 1:1 -s 1080x1080 output.mp4

@PauloLuan
Copy link
Author

PauloLuan commented Feb 25, 2023

Diminuir o tamanho:

Salvar num arquivo ~/encode.sh, conceder direito de execução e
executar desta forma (adaptar nomes de diretórios e arquivos para seu caso):

$ ~/encode.sh ~/Video/bigFile.mp4 ~/Video/smallFile.mp4
ffmpeg -i "$1" -vcodec h264 -acodec aac "$2"

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