#!/bin/bash # ffmpeg2theora-0.25 is static binary from # http://v2v.cc/~j/ffmpeg2theora/download.html # ffmpeg is ubuntu packaged binary base=$1 # we do this because of improper ffmpeg2theora handling of some dv input ffmpeg -i ${base}.dv -deinterlace -vcodec mpeg2video -qscale 1 -qmin 1 -intra -an -y ${base}.m2v ffmpeg -i ${base}.dv -acodec copy -vn -y ${base}.wav function theoraEncode() { src=$1 out=$2 vid=$3 aud=$4 wid=$5 hei=$6 ffmpeg2theora-0.25 ${src}.m2v --noaudio --two-pass -V ${vid} \ -x ${wid} -y ${hei} -o ${src}_tmp.ogv oggenc -b ${aud} ${src}.wav -o ${src}.ogg oggzmerge -o ${out} ${src}_tmp.ogv ${src}.ogg rm -f ${src}_tmp.ogv ${src}.ogg } function theoraTag() { ogv=$1 ## tags alb=$2 art=$3 yea=$4 tit=$5 cmp=$6 com=$7 vorbiscomment -a ${ogv} -t "ALBUM=${alb}" -t "ARTIST=${art}" -t "DATE=${yea}" \ -t "TITLE=${tit}" -t "COMPOSER=${cmp}" -t "DESCRIPTION=${com}" } function h264Encode() { src=$1 out=$2 vid=$3 aud=$4 wid=$5 hei=$6 ffmpeg -i ${src}.dv -deinterlace -an -pass 1 -vcodec libx264 \ -s ${wid}x${hei} -vpre fastfirstpass \ -b ${vid} -bt ${vid} -threads 0 -y -f mp4 /dev/null ffmpeg -i ${src}.dv -deinterlace -acodec libfaac -ab ${aud} -pass 2 \ -vcodec libx264 -s ${wid}x${hei} \ -vpre hq -b ${vid} -bt ${vid} -threads 0 -y -f mp4 ${out} rm -f x264_2pass.log ffmpeg2pass-0.log } function h264Tag() { mp4=$1 ## tags alb=$2 art=$3 yea=$4 tit=$5 cmp=$6 com=$7 TMP=${mp4}_tmp.mp4 mv -f ${mp4} ${TMP} mp4tags -A "${alb}" -a "${art}" -y "${yea}" -s "${tit}" -w "${cmp}" -g "Herpetology" ${TMP} qt-faststart ${TMP} ${mp4} rm -f ${TMP} } function lowQual() { base=$1 theoraEncode ${base} ${base}.ogv 768k 64k 384 288 h264Encode ${base} ${base}.mp4 768k 64k 384 288 } function sdQual() { base=$1 theoraEncode ${base} ${base}-sd.ogv 1536k 64k 640 480 h264Encode ${base} ${base}-sd.mp4 1536k 64k 640 480 } meta=0 if [ -f ${base}.meta ]; then meta=1 alb=`cat ${base}.meta |cut -d":" -f1` art=`cat ${base}.meta |cut -d":" -f2` yea=`cat ${base}.meta |cut -d":" -f3` tit=`cat ${base}.meta |cut -d":" -f4` cmp=`cat ${base}.meta |cut -d":" -f5` com=`cat ${base}.meta |cut -d":" -f6` fi [ -f ${base}.ogv ] && rm -f ${base}.ogv [ -f ${base}.mp4 ] && rm -f ${base}.mp4 lowQual ${base} if [ $meta -eq 1 ]; then theoraTag ${base}.ogv "${alb}" "${art}" "${yea}" "${tit}" "${cmp}" "${com}" h264Tag ${base}.mp4 "${alb}" "${art}" "${yea}" "${tit}" "${cmp}" "${com}" else mv -f ${base}.mp4 ${base}_tmp.mp4 qt-faststart ${base}_tmp.mp4 ${base}.mp4 rm -f ${base}_tmp.mp4 fi [ -f ${base}-sd.ogv ] && rm -f ${base}-sd.ogv [ -f ${base}-sd.mp4 ] && rm -f ${base}-sd.mp4 sdQual ${base} if [ $meta -eq 1 ]; then theoraTag ${base}-sd.ogv "${alb}" "${art}" "${yea}" "${tit}" "${cmp}" "${com}" h264Tag ${base}-sd.mp4 "${alb}" "${art}" "${yea}" "${tit}" "${cmp}" "${com}" else mv -f ${base}-sd.mp4 ${base}_tmp.mp4 qt-faststart ${base}_tmp.mp4 ${base}-sd.mp4 rm -f ${base}_tmp.mp4 fi rm -f ${base}.m2v ${base}.wav exit 0