From 4639372d4de5384e0d33963f4e03592a3563aeb9 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Mon, 19 Sep 2011 13:05:04 +0200 Subject: Use only ffmpeg and qt-faststart (not ffmpeg2theora or HandBrakeCLI). --- localvideowebencode | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file 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" <

Download Video: -open format Ogg, +open format Ogg, ${webm:+open format WebM,} closed Format MP4.

-- cgit v1.2.3