Skip to content

Instantly share code, notes, and snippets.

@derhuerst
Created April 1, 2015 11:12
Show Gist options
  • Save derhuerst/0db51ba39231d6529644 to your computer and use it in GitHub Desktop.
Save derhuerst/0db51ba39231d6529644 to your computer and use it in GitHub Desktop.
Convert any video to WebM and MP4 for HTML5 video
#!/bin/bash
# This script takes any (high resolution) video file as input and converts it to WebM (VP8 & Vorbis) and MP4 (H264 & AAC) for HTML5 <video>. For each format, it creates a high quality (`-hq`) and a low quality (`-lq`) version.
# ffmpeg has to be installed, see http://docs.sublimevideo.net/encode-videos-for-the-web for more instructions.
# Usage: videoToWeb.sh <inputfile>
# This is heavily inspired by
# - https://github.com/kornl/video-conversion/blob/master/convert_video_for_html_5.sh
# - https://github.com/mickro/video2html5/blob/master/video2html5.sh
# - http://diveintohtml5.info/video.html#webm-cli
file=`basename $1`
file="${file%.*}"
# high quality MP4
ffmpeg -i $1 -acodec libfaac -vcodec libx264 -vb 2000k -vf scale=iw/2:ih/2 -f mp4 $file.lq.mp4
# low quality MP4
ffmpeg -i $1 -acodec libfaac -vcodec libx264 -vb 8000k -f mp4 $file.mp4
# high quality WebM
ffmpeg -i $1 -acodec libvorbis -vcodec libvpx -vb 2000k -vf scale=iw/2:ih/2 -f webm $file.lq.webm
# low quality WebM
ffmpeg -i $1 -acodec libvorbis -vcodec libvpx -vb 8000k -f webm $file.webm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment