Skip to content

Instantly share code, notes, and snippets.

@michaelkirk
Created May 13, 2024 21:28
Show Gist options
  • Save michaelkirk/59d0ef3385dd4d63c61ef0115b7415c7 to your computer and use it in GitHub Desktop.
Save michaelkirk/59d0ef3385dd4d63c61ef0115b7415c7 to your computer and use it in GitHub Desktop.
Resize and re-encode a video to something appropriate for a GH upload or other small file sharing.
set -x
set -e
BIN_NAME=$0
function usage {
cat <<EOS
Usage:
$BIN_NAME <video file> [width_scale]
Example:
$BIN_NAME foo.mov
EOS
}
INPUT_FILE=$1
if [ -z "${INPUT_FILE}" ]
then
usage
exit 1
fi
# default output resolution
DEFAULT_WIDTH_SCALE=640
WIDTH_ARG=$2
WIDTH_SCALE="${WIDTH_ARG:-$DEFAULT_WIDTH_SCALE}"
# WIDTH_SCALE=-2
# WIDTH_SCALE=420
#HEIGHT_SCALE=480
HEIGHT_SCALE=-2
OUTPUT_FILE="${INPUT_FILE}.mp4"
ffmpeg -i "${INPUT_FILE}" -vf scale="${WIDTH_SCALE}:${HEIGHT_SCALE}" -qscale:v 0 "${OUTPUT_FILE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment