Skip to content

Instantly share code, notes, and snippets.

@halfninja
Created April 1, 2012 14:17
Show Gist options
  • Save halfninja/2275548 to your computer and use it in GitHub Desktop.
Save halfninja/2275548 to your computer and use it in GitHub Desktop.
#!/bin/bash
## Encode a file to an MP4 that my TV can play.
## Assumes SD card is inserted at /media/NO_NAME,
## and Handbrake CLI is installed (apt-get install handbrake-cli).
## See "HandBrakeCLI -z" for list of presets.
SDCARD=/media/NO_NAME
HANDBRAKE_PRESET=Normal
function die() {
echo "$@" 1>&2
exit 1
}
function usage() {
die "Usage: encode_for_tv FILENAME"
}
if [[ ! -d "$SDCARD" ]]; then
die "Target '$SDCARD' not found."
fi
FILE=$1
if [[ "$FILE" == "" ]]; then
usage
elif [[ ! -f "$FILE" ]]; then
die "File '$FILE' does not exist."
fi
DEST=$SDCARD/`basename "${FILE%.*?}.mp4"`
if [[ -f "$DEST" ]]; then
die "Destination '$DEST' already exists, not overwriting."
fi
echo "Encoding file $FILE..."
echo "Encoding to $DEST..."
HandBrakeCLI -i "$FILE" -o "$DEST" --preset=$HANDBRAKE_PRESET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment