Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
automated conversion of a file to all three html5 compatible video formats - h.264, ogg, and webm
#!/bin/sh
####################################
# Output file for HTML5 video #
# Requirements: #
# - handbrakecli #
# - ffmpeg #
# - ffmpeg2theora #
# #
# usage: #
# ./html5video.sh infile.mp4 #
# #
###################################
target_directory='converted'
file=`basename $1`
filename=${file%.*}
filepath=`dirname $1`
destination="$filepath/$target_directory"
if ! test -d "$destination"
then
mkdir $destination
fi
HandBrakeCLI -i $1 -o $destination/$filename.mp4 --encoder x264 --vb 900 --ab 128 --optimize
ffmpeg2theora $destination/$filename.mp4
mv $destination/$filename.ogv $destination/$filename.ogg
ffmpeg -i $destination/$filename.mp4 -acodec libvorbis -vcodec libvpx $destination/$filename.webm
@catsby

This comment has been minimized.

Copy link

catsby commented Feb 8, 2011

I had to add "$destination/$filename.webm" to the end of line 29 to get this to convert to webm format

@markupboy

This comment has been minimized.

Copy link
Owner Author

markupboy commented Feb 8, 2011

Good catch, must've missed that on the copy and paste.

@juniovitorino

This comment has been minimized.

Copy link

juniovitorino commented Feb 8, 2011

I did this one to convert any video for h264 flv in linux some time ago. It could be changed to generate any format you want.
https://gist.github.com/328482

@liamcurry

This comment has been minimized.

Copy link

liamcurry commented May 16, 2012

Newer versions of ffmpeg can convert to all HTML5 video types, without ffmpeg2theora or HandBrakeCLI. I simplified the script in this fork: https://gist.github.com/2696512

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.