-
-
Save rodneyrehm/1439768 to your computer and use it in GitHub Desktop.
Convert videos to proper formats for HTML5 video on Linux shell using ffmpeg.
This file contains 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 | |
# configure stuff | |
width=640 | |
height=320 | |
size=$width"x"$height | |
# show help | |
if [[ "$1" == "" || "$1" == "-h" || "$1" == "--help" ]]; then | |
echo "USAGE: "; | |
echo "$(basename $0) [wmo] video.avi"; | |
echo " w: WebM"; | |
echo " m: MP4"; | |
echo " o: OGG"; | |
exit 1; | |
fi | |
# parameters are optional, make all targets if none specified | |
if [ "$2" = "" ]; then | |
f=$1; | |
p="wmo"; | |
else | |
f=$2; | |
p=$1; | |
fi | |
# file name mangling | |
dir=$(dirname $f) | |
file=$(basename $f) | |
name=${file%.*} | |
extension=${file##*.} | |
# abort if file doesn't exist | |
if [ ! -e $f ]; then echo "File $f not found"; exit 1; fi | |
if [[ "$p" == *w* ]]; then | |
# webm | |
ffmpeg -i $f -f webm -vcodec libvpx -acodec libvorbis -ab 128000 -crf 22 -s $size "$dir/$name.webm" | |
fi | |
if [[ "$p" == *m* ]]; then | |
# mp4 | |
ffmpeg -i $f -acodec aac -strict experimental -ac 2 -ab 128k -vcodec libx264 -vpre slow -f mp4 -crf 22 -s $size "$dir/$name.mp4" | |
fi | |
if [[ "$p" == *o* ]]; then | |
# ogg (if you want to support older Firefox) | |
ffmpeg2theora $f -o "$dir/$name.ogv" -x $width -y $height --videoquality 5 --audioquality 0 --frontend | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just for the record: on my Ubuntu 11.10, it needs
#!/usr/bin/env bash
instead of#!/bin/sh
.