-
-
Save shshaw/be44096527aab3651b77 to your computer and use it in GitHub Desktop.
HTML5 Video format conversion with FFmpeg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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