Skip to content

Instantly share code, notes, and snippets.

@mmazzarolo
Created September 6, 2020 13:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmazzarolo/a1625082e17ea93c259493c76b529659 to your computer and use it in GitHub Desktop.
Save mmazzarolo/a1625082e17ea93c259493c76b529659 to your computer and use it in GitHub Desktop.
Resize videos keeping the aspect ratio (shows black bar padding where needed)
#!/bin/bash
input="input.mp4"
output="output.mp4"
color="black"
while getopts ":i:o:w:h:c:" opt; do
case $opt in
i) input="$OPTARG"
;;
o) output="$OPTARG"
;;
w) width="$OPTARG"
;;
h) height="$OPTARG"
;;
c) color="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
ffmpeg -i $input -vf "scale=w=${width}:h=${height}:force_original_aspect_ratio=decrease,pad=${width}:${height}:(ow-iw)/2:(oh-ih)/2:color=${color}" $output
@mmazzarolo
Copy link
Author

My main usage was for resizing iOS captures for the app store previews:
Usage:

ffmpeg_resize.sh -i input.mp4 -o output-1080x1920.mp4 -w 1080 -h 1920 -c white

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