Skip to content

Instantly share code, notes, and snippets.

@seblavoie
Created February 6, 2014 18:57
Show Gist options
  • Save seblavoie/8850410 to your computer and use it in GitHub Desktop.
Save seblavoie/8850410 to your computer and use it in GitHub Desktop.
Bash aliases to create webm
makeWebm() {
FILE=$1
BITRATE=${2:-'3450'}
SIZE=${3:-'1280x720'}
FILENAME=${FILE%%.*}
ffmpeg -i ${FILE} -acodec libvorbis -ac 2 -ab 96k -ar 44100 -b ${BITRATE}k -s ${SIZE} ${FILENAME}.webm
}
makeWebms() {
BITRATE=${1:-'3450'}
SIZE=${2:-'1280x720'}
for file in $(find . -name "*.mp4"); do ffmpeg -i "$file" -acodec libvorbis -ac 2 -ab 96k -ar 44100 -b ${BITRATE}k -s ${SIZE} "${file/.mp4/.webm}"; done
}
makeWebm() {
FILE=$1
DIMENSIONS=`$(ffmpeg -i ${FILE} 2>&1 | perl -lane 'print $1 if /([0-9]{2,}x[0-9]{2,})/')`
SIZE=${3:-${DIMENSIONS}}
CALCULATEDBITRATE=`ffprobe -show_streams -i ${FILE} | grep -m 1 "bit_rate" | sed 's|[^0-9]||g'`
CALCULATEDBITRATE=`echo $((${CALCULATEDBITRATE} / 1024))`
BITRATE=${2:-${CALCULATEDBITRATE}}
FILENAME=${FILE%%.*}
ffmpeg -i ${FILE} -acodec libvorbis -ac 2 -ab 96k -ar 44100 -b ${BITRATE}k -s ${SIZE} ${FILENAME}.webm
}
makeWebms() {
for FILE in $(find . -name "*.mp4")
do
WIDTH=`ffprobe -show_streams -i ${FILE} | grep -m 1 "width" | sed 's|[^0-9]||g'`
HEIGHT=`ffprobe -show_streams -i ${FILE} | grep -m 1 "height" | sed 's|[^0-9]||g'`
DIMENSIONS="${WIDTH}x${HEIGHT}"
BITRATE=`ffprobe -show_streams -i ${FILE} | grep -m 1 "bit_rate" | sed 's|[^0-9]||g'`
BITRATE=`echo $((${BITRATE} / 1024))`
FILE=`echo ${FILE} | sed 's|\.\/||g'`
makeWebm "${FILE}" ${BITRATE} ${DIMENSIONS}
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment