Skip to content

Instantly share code, notes, and snippets.

@kjlape
Last active May 16, 2017 16:14
Show Gist options
  • Select an option

  • Save kjlape/5550c12ae831e295a9a358f36049a0f9 to your computer and use it in GitHub Desktop.

Select an option

Save kjlape/5550c12ae831e295a9a358f36049a0f9 to your computer and use it in GitHub Desktop.
HTML5 FFMPEG Video Conversion
#!/bin/sh
# Modified from original implementation:
# https://gist.github.com/liamcurry/2696512
# Requires ffmpeg with codec plugins
# On Mac:
# brew install ffmpeg --with-libvpx --with-theora --with-libogg --with-libvorbis --with-webp --with-rtmpdump --with-openh264 --with-fdk-aac
# Output file for HTML5 video
# usage: this_file.sh input.mp4 640x360
# sample_flags="-ss 30 -t 8"
target_directory='converted'
file=`basename $1`
filename=${file%.*}
filepath=`dirname $1`
destination="$filepath/$target_directory"
if ! test -d "$destination"
then
mkdir $destination
fi
# Ogg/Theora
ffmpeg -i $1 \
-codec:a libvorbis \
-qscale:a 4 \
-codec:v libtheora \
-qscale:v 3 \
$sample_flags \
-s $2 $destination/$filename.ogv
# WebM/vp8
ffmpeg -i $1 \
-acodec libvorbis \
-qscale:a 4 \
-c:v libvpx \
-crf 10 \
-b:v 2M \
$sample_flags \
-s $2 $destination/$filename.webm
# MP4/h264
ffmpeg -y -i $1 \
-acodec aac -ab 96k \
-vcodec libx264 \
-preset medium \
-b:v 2M \
-pass 1 \
$sample_flags \
-s $2 -f mp4 /dev/null && \
ffmpeg -y -i $1 \
-acodec aac -ab 96k \
-vcodec libx264 \
-preset medium \
-b:v 2M \
-pass 2 \
$sample_flags \
-s $2 $destination/$filename.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment