Skip to content

Instantly share code, notes, and snippets.

@miroslavradojevic
Last active February 14, 2021 12:12
Show Gist options
  • Save miroslavradojevic/8ee7e8c4c7f773190c22cdc25d1d6479 to your computer and use it in GitHub Desktop.
Save miroslavradojevic/8ee7e8c4c7f773190c22cdc25d1d6479 to your computer and use it in GitHub Desktop.
Use ffmpeg to modify .mp4 videos with terminal commands
# https://video.stackexchange.com/questions/4563/how-can-i-crop-a-video-with-ffmpeg
# https://superuser.com/questions/841235/how-do-i-use-ffmpeg-to-get-the-video-resolution
# To get mp4 video resolution
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 input.mp4
# Use crop filter
ffmpeg -i input.mp4 -filter:v "crop=out_w:out_h:x:y" output.mp4
# To crop a 80×60 section, starting from position (200, 100)
ffmpeg -i input.mp4 -filter:v "crop=80:60:200:100" -c:a copy output.mp4
# To crop the bottom right quarter
ffmpeg -i input.mp4 -filter:v "crop=in_w/2:in_h/2:in_w/2:in_h/2" -c:a copy output.mp4
# Crop 20 pixels from the top, and 20 from the bottom
ffmpeg -i in.mp4 -filter:v "crop=in_w:in_h-40" -c:a copy out.mp4
# To speed up video
# 4x
ffmpeg -i input.mp4 -vf "setpts=0.25*PTS" output.mp4
# 2x
ffmpeg -i input.mp4 -vf "setpts=0.5*PTS" output.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment