Skip to content

Instantly share code, notes, and snippets.

@shshaw shshaw/html5video.sh forked from liamcurry/html5video.sh
Last active Aug 29, 2015

Embed
What would you like to do?
HTML5 Video format conversion with FFmpeg
#!/bin/sh
# Output file for HTML5 video
# Requirements: ffmpeg .6+ with libvorbis, theora and libvpx
# ( Install via brew with `brew install ffmpeg --with-libvorbis --with-libvpx --with-theora` )
# Usage: `./html5video.sh infile.mp4`
# Optional parameters:
# `./html5video.sh infile.mp4 -y` to force overwriting existing videos
# `./html5video.sh infile.mp4 -n 640x480` to force an output size
target_directory='converted'
file=`basename $1`
filename=${file%.*}
filepath=`dirname $1`
destination="$filepath/$target_directory"
# default to no overwrite
overwrite='-n'
[ -n "${2}" ] && overwrite="${2}"
# default to no size parameter
size=''
[ -n "${3}" ] && size="-s ${3}"
if ! test -d "$destination"
then
mkdir $destination
fi
#######################
# MP4/h264
#######################
ffmpeg -i $1 \
-acodec libfaac -b:a 96k \
-codec:v libx264 -profile:v high -preset slower -b:v 750k -maxrate 750k -bufsize 1000k \
-pix_fmt yuv420p \
-threads 0 \
$size $overwrite \
$destination/$filename.mp4 \
-loglevel warning -stats
#######################
# Ogg/Theora
#######################
ffmpeg -i $1 \
-acodec libvorbis -ac 2 -b:a 96k -ar 44100 \
-vcodec libtheora -qscale:v 8 -b:v 1M \
$size $overwrite \
$destination/$filename.ogv \
-loglevel warning -stats
#######################
# WebM/vp8
#######################
ffmpeg -i $1 \
-acodec libvorbis -ac 2 -b:a 96k -ar 44100 \
-b:v 1M \
$size $overwrite \
$destination/$filename.webm \
-loglevel warning -stats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.