summaryrefslogtreecommitdiff
path: root/localvideowebencode
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2014-09-30 12:29:16 +0200
committerJonas Smedegaard <dr@jones.dk>2014-09-30 12:29:16 +0200
commitf657ec6b5565670b7a20c8e34e7f74cc4f8fbc98 (patch)
tree4c5c068096faa65754497d8308c421024f8c80e4 /localvideowebencode
parent4c01f159cb3d7cb961cbe85d200d1d25386989e4 (diff)
Add option --compression.
Diffstat (limited to 'localvideowebencode')
-rwxr-xr-xlocalvideowebencode55
1 files changed, 45 insertions, 10 deletions
diff --git a/localvideowebencode b/localvideowebencode
index 8befac3..4a940de 100755
--- a/localvideowebencode
+++ b/localvideowebencode
@@ -91,6 +91,8 @@ html favoring open formats with optional non-JavaScript Flash fallback.
(default: start at first frame)
--sample-length Create sample of specified length, in frames
(default: 150 frames i.e. approx. 5s)
+ --compression Optimize for quality or speed: normal dirty hq
+ (default: normal)
-h, --help This help text
Examples:
@@ -122,9 +124,10 @@ exit1() {
formats=webm,vp9,mp4
samplestart=0
samplelength=150
+compression=normal
# parse cmdline options
-TEMP="`getopt -s sh -o hp:s:a:r:b:t: -l help,profile:,size:,aspect:,rate:,video:,refbpp:,formats:,audio:,audioprefilter:,loudness,loudness-data:,filter:,stem:,title:,sample,sample-start:,sample-length: -n "$PRG" -- "$@"`" || exit1 "Internal getopt error."
+TEMP="`getopt -s sh -o hp:s:a:r:b:t: -l help,profile:,size:,aspect:,rate:,video:,refbpp:,formats:,audio:,audioprefilter:,loudness,loudness-data:,filter:,stem:,title:,sample,sample-start:,sample-length:,compression: -n "$PRG" -- "$@"`" || exit1 "Internal getopt error."
eval set -- "$TEMP"
while true ; do
case "$1" in
@@ -146,6 +149,7 @@ while true ; do
--sample) sample=yes; shift;;
--sample-start) sample=yes; samplestart="$2"; shift 2;;
--sample-length) sample=yes; samplelength="$2"; shift 2;;
+ --compression) compression="$2"; shift 2;;
--) shift; break;;
*) exit1 "Internal error resolving options.";;
esac
@@ -163,6 +167,37 @@ infile_first=$(perl -e 'print shift @ARGV' $infiles)
stem=${stem:-$(basename "$infile_first" | perl -pe 's/\.[^.]*//')}
title=${title:-$stem}
+# resolve quality/speed hints
+multipass=yes
+speedpreset_h264=medium
+crf_vp8=10
+crf_vp9=10
+crf_h264=23
+qscale_theora=5
+cpu_vp8=3
+cpu_vp9=5
+case "$compression" in
+ normal) :;;
+ dirty)
+ multipass=
+ speedpreset_h264=veryfast
+ crf_vp8=0
+ crf_vp9=0
+ qscale_theora=3
+ cpu_vp8=5
+ ;;
+ hq)
+ speedpreset_h264=veryslow
+ crf_vp8=10
+ crf_vp9=10
+ qscale_theora=6
+ cpu_vp8=0
+ cpu_vp9=1
+ ;;
+ *) exit1 "Unknown compression optimization \"$video\".";;
+esac
+
+
# parse/resolve size and framerate
case "$profile" in
'') :;;
@@ -325,12 +360,12 @@ esac
melt="melt -progress"
_melt_sample="$infile_first ${sample:+in=${samplestart:-0} out=$((${samplestart:-0} + samplelength))}"
_melt_video="progressive=1${framerate:+ frame_rate_den="$framerate_den" frame_rate_num="$framerate_num"}${size:+ s=${width:+$width}x${height:+$height}}${aspect:+ aspect=$aspect}"
-_melt_ogg="$_melt_video f=ogg vcodec=libtheora${bitrate:+ vb=$bitrate} qscale=5"
-_melt_h264="$_melt_video f=mp4 vcodec=libx264 vpreset=medium vprofile=baseline${x264tune:+ tune=$x264tune} threads=0 movflags=+faststart crf=23"
-_melt_webm="$_melt_video f=webm vcodec=libvpx vpreset=libvpx-$webmpreset${bitrate:+ vb=$bitrate} crf=10 cpu-used=3"
+_melt_ogg="$_melt_video f=ogg vcodec=libtheora${bitrate:+ vb=$bitrate} qscale=$qscale_theora"
+_melt_h264="$_melt_video f=mp4 vcodec=libx264 vpreset=$speedpreset_h264 vprofile=baseline${x264tune:+ tune=$x264tune} threads=0 movflags=+faststart crf=$crf_h264"
+_melt_webm="$_melt_video f=webm vcodec=libvpx vpreset=libvpx-$webmpreset${bitrate:+ vb=$bitrate} crf=$crf_vp8 cpu-used=$cpu_vp8"
_melt_img="$_melt_video f=image2"
# CRF ignored with libvpx 1.3
-_melt_vp9="$_melt_video f=webm vcodec=libvpx-vp9 vpreset=libvpx-$webmpreset${bitrate_vp9:+ vb=$bitrate_vp9} crf=10 cpu-used=5"
+_melt_vp9="$_melt_video f=webm vcodec=libvpx-vp9 vpreset=libvpx-$webmpreset${bitrate_vp9:+ vb=$bitrate_vp9} crf=$crf_vp9 cpu-used=$cpu_vp9"
_melt_audio="${channels:+ac=$channels}"
# limit (i.e. avoid peaks "clipping")
_melt_postfilters_audio="${limit:+-filter ladspa.1077}"
@@ -339,8 +374,8 @@ _melt_opus="$_melt_audio acodec=libopus${channels:+ ab=$(($channels*$bitrate_opu
_melt_aac="$_melt_audio acodec=aac${channels:+ ab=$(($channels*$bitrate_aac))k}"
avconv="avconv -threads auto -y -v warning"
-_avconv_vp8="-c:v libvpx -pre:v libvpx-$webmpreset${bitrate:+ -b:v $bitrate} -crf 10 -cpu-used 3"
-_avconv_vp9="-c:v libvpx-vp9 -pre:v libvpx-$webmpreset${bitrate_vp9:+ -b:v $bitrate_vp9} -crf 10 -cpu-used 5"
+_avconv_vp8="-c:v libvpx -pre:v libvpx-$webmpreset${bitrate:+ -b:v $bitrate} -crf $crf_vp8 -cpu-used $cpu_vp8"
+_avconv_vp9="-c:v libvpx-vp9 -pre:v libvpx-$webmpreset${bitrate_vp9:+ -b:v $bitrate_vp9} -crf $crf_vp9 -cpu-used $cpu_vp9"
# resolve EBU R128 audio normalizing
if [ -n "$loudness" ] && [ -z "$_melt_loudness" ]; then
@@ -350,7 +385,7 @@ if [ -n "$loudness" ] && [ -z "$_melt_loudness" ]; then
echo "Loudness data: $_melt_loudness"
fi
-if [ -n "$webm$vp9" ]; then
+if [ -n "$multipass" ] && [ -n "$webm$vp9" ]; then
echo "Analyzing complexity for WebM..."
$melt ${_melt_sample:-$infiles} $filters \
-consumer avformat:pipe:1 $_melt_video f=yuv4mpegpipe pix_fmt=yuv420p an=1 audio_off=1 \
@@ -367,8 +402,8 @@ $melt ${_melt_sample:-$infiles} \
$filters${channels:+ $_melt_postfilters_audio} \
${ogg:+-consumer avformat:$stem.ogv $_melt_ogg $_melt_vorbis} \
${mp4:+-consumer avformat:$stem.mp4 $_melt_h264 $_melt_aac} \
- ${webm:+-consumer avformat:$stem.webm $_melt_webm pass=2 passlogfile=${stem}_vp8 $_melt_vorbis} \
- ${vp9:+-consumer avformat:${stem}_vp9.webm pass=2 passlogfile=${stem}_vp9 $_melt_vp9 $_melt_opus}
+ ${webm:+-consumer avformat:$stem.webm $_melt_webm${multipass:+ pass=2 passlogfile=${stem}_vp8} $_melt_vorbis} \
+ ${vp9:+-consumer avformat:${stem}_vp9.webm${multipass:+ pass=2 passlogfile=${stem}_vp9} $_melt_vp9 $_melt_opus}
if [ -n "$mp4" ] && [ -z "$melt_recent" ]; then
mv "$stem.mp4" "$stem.mp4"~