Created
June 20, 2011 19:35
-
-
Save nuex/1036376 to your computer and use it in GitHub Desktop.
make a bunch of html5 video formats from a source video
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 | |
| # html5vid.sh | |
| # | |
| # Encode an input video to multiple html5-ready formats: | |
| # - webm | |
| # - ogv | |
| # - mp4 | |
| # - png (50th frame) | |
| # | |
| # html5vid.sh requires the following utilties: | |
| # - ffmpeg | |
| # - ffmpeg2theora | |
| # - ImageMagick | |
| # - HandBrakeCLI | |
| filename=$1 | |
| dimensions="320x240" | |
| output_directory= | |
| usage() { | |
| echo "usage: $0 myvideo.mp4 [-d dimensions] [-o outputdirectory]" | |
| } | |
| # Exit if no options are given | |
| [ -z $filename ] && usage && exit 1 | |
| # Exit if input file doesn't exist | |
| [ ! -f $filename ] && echo "error: input file \"$filename\" doesn't exist" && exit 1 | |
| shift | |
| while getopts d:o: opt; do | |
| case $opt in | |
| d) dimensions="$OPTARG";; | |
| o) output_directory="$OPTARG";; | |
| ?) usage | |
| exit 1;; | |
| esac | |
| done | |
| # TODO assumes input file format is mp4 | |
| video_name=$(echo $filename | sed "s/.mp4//g") | |
| # If no output directory is given, set it to the video name | |
| [ -z $output_directory ] && output_directory=$video_name | |
| filepath=$(pwd) | |
| original=$filepath/$filename | |
| tmpdir=$output_directory/.tmp | |
| mkdir -p $output_directory $tmpdir | |
| cd $tmpdir | |
| width=$(echo $dimensions | awk '{split($0,w,"x"); print w[1]}') | |
| video_bitrate=614400 | |
| gop_size=250 | |
| # webm | |
| # webm: first pass | |
| ffmpeg -pass 1 -passlogfile $video_name -threads 16 -keyint_min 0 -g $gop_size -skip_threshold 0 -qmin 1 -qmax 51 -i $original -vcodec libvpx -s $dimensions -b $video_bitrate -aspect 4:3 -an -y $video_name.webm | |
| # webm: second pass | |
| ffmpeg -pass 2 -passlogfile $video_name -threads 16 -keyint_min 0 -g $gop_size -skip_threshold 0 -qmin 1 -qmax 51 -i $original -vcodec libvpx -s $dimensions -b $video_bitrate -aspect 4:3 -acodec libvorbis -y $video_name.webm | |
| # encode ogv | |
| # TODO use ffmpeg to do this and remove ffmpeg2theora dependency | |
| ffmpeg2theora -o $tmpdir/$video_name.ogv --videoquality 5 --audioquality 1 --max_size $dimensions $original | |
| # encode mp4 | |
| # TODO use ffmpeg to do this and remove HandBrakeCLI dependency | |
| HandBrakeCLI --preset "iPhone & iPod Touch" --width $width --vb 600 --turbo --input $original --output $video_name.mp4 | |
| # make png | |
| # make a png file by extracting the Nth frame from the source video | |
| convert -resize $dimensions $original[50] $video_name.png | |
| # move files to parent directory | |
| for ext in webm png ogv mp4; do | |
| [ -z $video_name.$ext ] && mv $video_name.$ext ../ | |
| done | |
| # cleanup | |
| rm -rf $tmpdir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment