Skip to content

Instantly share code, notes, and snippets.

@SudhansuuRanjan
Forked from mmazzarolo/ffmpeg_resize.sh
Created November 12, 2024 21:25
Show Gist options
  • Select an option

  • Save SudhansuuRanjan/23da7d65afd59788bc74f20cc77f57e4 to your computer and use it in GitHub Desktop.

Select an option

Save SudhansuuRanjan/23da7d65afd59788bc74f20cc77f57e4 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment