diff options
-rwxr-xr-x | localvideowebencode | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/localvideowebencode b/localvideowebencode index 0d5868d..53d133d 100755 --- a/localvideowebencode +++ b/localvideowebencode @@ -105,21 +105,51 @@ title=${title:-$filebase} # TODO: Check and fail if all needed tools are not available +_ffmpeg() { + passes="$1"; shift + ext="$1"; shift + [ ! -f "$filebase.$ext" ] || exit1 "output file \"$filebase.$ext\" already exist. Remove it and try again." + case $passes in + 0) + ffmpeg -i "$infile" $opts "$@" -f "$ext" -y "$filebase.$ext" + ;; + 1) + [ ! -f "$filebase"-*.log ] || exit1 "logfiles already exist. Remove them (or wait for that other process to complete) and try again." + ffmpeg -i "$infile" -pass 1 -passlogfile "$filebase" "$@" -an -f "$ext" -y /dev/null + ;; + 2) + [ -f "$filebase"-*.log ] || exit1 "logfiles missing. Pass 2 cannot succeed without a prior pass 1." + ffmpeg -i "$infile" -pass 2 -passlogfile "$filebase" "$@" -y "$filebase.$ext" + rm "$filebase"-*.log + case $ext in + mp4) + mv "$filebase.$ext" "$filebase.$ext"~ + qt-faststart "$filebase.$ext"~ "$filebase.$ext" + [ -f "$filebase.$ext" ] && rm "$filebase.$ext"~ || exit1 "failed to optimize with qt-faststart." + ;; + esac + ;; + esac +} + +opts_common="-threads 0 -b ${bitrate}k -s $size -aspect $aspect" +opts_audio="-ac 2 -ar 44100 -ab 96k" +opts_webm="-vcodec libvpx -keyint_min 0 -g 250 -skip_threshold 0" + ## Theora/Vorbis/Ogg -ffmpeg2theora --videobitrate "$bitrate" --max_size "$size" --aspect "$aspect" --output "$filebase.ogv" "$infile" +_ffmpeg 0 ogg $opts_common -vcodec libtheora -acodec libvorbis $opts_audio ## H.264/AAC/MP4 -HandBrakeCLI --preset "iPhone & iPod Touch" --vb "$bitrate" ${width:+--maxWidth "$width"} ${height:+--maxHeight "$height"} --two-pass --turbo --optimize --input "$infile" --output "$filebase.mp4" +_ffmpeg 1 mp4 $opts_common -vcodec libx264 -vpre medium_firstpass -vpre baseline +_ffmpeg 2 mp4 $opts_common -vcodec libx264 -vpre medium -vpre baseline -acodec libvo_aacenc $opts_audio ## VP8/Vorbis/WebM ! ffmpeg -codecs | grep -iw vp8 || webm=yes -# FIXME: check and fail if logfiles exist already -[ -z "$webm" ] || ffmpeg -pass 1 -passlogfile "$infile" -threads 16 -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -i "$infile" -vcodec libvpx -b "$bitrate"k -s "$size" -aspect "$aspect" -an -f webm -y NUL -[ -z "$webm" ] || ffmpeg -pass 2 -passlogfile "$infile" -threads 16 -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -i "$infile" -vcodec libvpx -b "$bitrate"k -s "$size" -aspect "$aspect" -acodec libvorbis -ac 2 -y "$filebase.webm" -rm "$infile"-*.log +[ -z "$webm" ] || _ffmpeg 1 webm $opts_common $opts_webm +[ -z "$webm" ] || _ffmpeg 2 webm $opts_common $opts_webm -acodec libvorbis $opts_audio ## JPEG preview -ffmpegthumbnailer -s0 -i "$filebase.ogv" -o "$filebase.jpg" +ffmpegthumbnailer -s0 -i "$filebase.ogg" -o "$filebase.jpg" # TODO: resolve flash player to use [ -z "$flashplayer" ] || flash=yes @@ -128,7 +158,7 @@ cat >"$filebase.html" <<EOF <!-- Video for Everybody, Kroc Camen of Camen Design --> <video width="$width" height="$height" preload controls> <source src="$filebase.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /> -<source src="$filebase.ogv" type='video/ogg; codecs="theora, vorbis"' /> +<source src="$filebase.ogg" type='video/ogg; codecs="theora, vorbis"' /> ${webm:+<source src="$filebase.webm" type='video/webm; codecs="vp8, vorbis"' /> }${flash:+<object width="$width" height="$heightplus" type="application/x-shockwave-flash" data="$flashplayer.swf"> <param name="movie" value="$flashplayer.swf" /> @@ -138,7 +168,7 @@ ${webm:+<source src="$filebase.webm" type='video/webm; codecs="vp8, vorbis"' /> ${flash:+</object> }</video> <p><strong>Download Video:</strong> -open format <a href="$filebase.ogv">Ogg</a>, +open format <a href="$filebase.ogg">Ogg</a>, ${webm:+open format <a href="$filebase.webm">WebM</a>,} closed Format <a href="$filebase.mp4">MP4</a>. </p> |