summaryrefslogtreecommitdiff
path: root/localvideowebencode
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2014-10-04 00:07:50 +0200
committerJonas Smedegaard <dr@jones.dk>2014-10-04 00:07:50 +0200
commit159fb1c842063bbacb9f7af7cd8f246ebd9c1ac4 (patch)
tree69dbaa93d3d21604857d9102528cad3373d3ab17 /localvideowebencode
parent489b4217405ef24177d204eca31e69051a277d84 (diff)
Fix downmix audio channels late if potentially disturbing a filter.
Diffstat (limited to 'localvideowebencode')
-rwxr-xr-xlocalvideowebencode67
1 files changed, 46 insertions, 21 deletions
diff --git a/localvideowebencode b/localvideowebencode
index ad6b15c..b60b0d1 100755
--- a/localvideowebencode
+++ b/localvideowebencode
@@ -354,20 +354,18 @@ quality_vorbis=3
bitrate_opus=48
bitrate_aac=64
-channels=-1
-maxchannels=2
case "$audio" in
music)
opusapp=audio
;;
hqspeech)
- channels=1
+ stereo=yes
quality_vorbis=1
bitrate_opus=32
opusapp=voip
;;
speech)
- channels=1
+ mono=yes
quality_vorbis=1
bitrate_opus=32
compress=yes
@@ -376,16 +374,40 @@ case "$audio" in
opusapp=voip
;;
silence)
- channels=0
+ silence=yes
;;
'')
:
;;
*) exit1 "Unknown audio style \"$audio\".";;
esac
-[ $channels -ge 0 ] || channels=$(avprobe -v warning -show_streams "$infile_first" | perl -ne 's/channels=// and print $_' || echo -1)
-[ $channels -le $maxchannels ] || channels=$maxchannels
-[ $channels -gt 0 ] || channels=
+# inspect channels only if potentially needing downmix/silence
+if [ -n "$stereo$mono$silence" ]; then
+ channels=$(avprobe -v warning -show_streams "$infile_first" \
+ | perl -ne 's/channels=// and print $_' || echo -1)
+fi
+# adapt channel count and flags to reflect actual downmix/silence need
+[ -z "$stereo" ] || [ $channels -le 2 ] || { stereo= && channels=2; }
+[ -z "$mono" ] || [ $channels -le 1 ] || { mono= && channels=1; }
+[ -z "$silence" ] || [ $channels -le 0 ] || { silence= && channels=0; }
+[ -z "$channels" ] || [ $channels -gt 0 ] || channels=
+if [ -n "$stereo$mono$silence" ]; then
+ # melt cannot downmix with (stereo?) filters applied (bug#763911)
+ if [ -n "$audioprefilters$compress$loudness$limit$filters" ]; then
+ if [ -z "${webm:+$use_oggenc}${webm_vp9:+$use_opusenc}" ]; then
+ downmix_avconv=yes
+ else
+ downmix_oggenc=yes
+ downmix_oggenc=yes
+ fi
+ else
+ downmix_melt=yes
+ fi
+fi
+
+use_vpxenc=yes
+#use_oggenc=yes
+#use_opusenc=yes
# generic options
melt="melt -progress"
@@ -398,8 +420,11 @@ _melt_sample="$infile_first ${sample:+in=${samplestart:-0} out=$((${samplestart:
# filter options
_melt_video="progressive=1${framerate:+ frame_rate_num="$framerate_num" frame_rate_den="$framerate_den"}${size:+ s=${width:+$width}x${height:+$height}}${aspect:+ aspect=$aspect}"
_avconv_video="${do_deinterlace:+-filter:v yadif}${framerate:+ -r $framerate_num/$framerate_den}${size:+ -s ${width:+$width}x${height:+$height}}${aspect:+ -aspect $aspect}"
-_melt_audio="${channels:+ac=$channels}"
-_avconv_audio="${channels:+-ac $channels}"
+_melt_downmix="${downmix_melt:+ac=$channels}"
+_avconv_downmix="${downmix_avconv:+-ac $channels}"
+# FIXME: how to downmix to stereo?
+_oggenc_downmix="${downmix_oggenc:+${mono:+--downmix}}"
+_opusenc_downmix="${downmix_opusenc:+${stereo:+--downmix-stereo}${mono:+--downmix-mono}}"
# limit (i.e. avoid peaks "clipping")
_melt_postfilters_audio="${limit:+-filter ladspa.1077}"
@@ -413,20 +438,20 @@ _melt_vp9="vcodec=libvpx-vp9 vpreset=$sizepreset_vpx${bitrate_vp9:+ vb=$bitrate_
_avconv_vp9="-c:v libvpx-vp9 -pre:v $sizepreset_vpx${bitrate_vp9:+ -b:v $bitrate_vp9 -minrate $((bitrate_vp9/20)) -maxrate $((bitrate_vp9*12))} -crf $crf_vp9 -cpu-used $cpu_vp9"
_vpxenc_vp9="--codec=vp9${bitrate_vp9:+ --target-bitrate=$bitrate_vp9} --good --end-usage=cq --cq-level=$crf_vp9 --cpu-used=$cpu_vp9 $_vpxenc_vpx --tile-columns=$webm_tokenparts_log2 --tile-rows=$webm_tokenparts_log2"
_melt_h264="vcodec=libx264 vpreset=$speedpreset_h264 vprofile=baseline${x264tune:+ tune=$x264tune} threads=0 movflags=+faststart crf=$crf_h264"
-_melt_vorbis="$_melt_audio acodec=libvorbis aq=$quality_vorbis"
-_avconv_vorbis="-c:a libvorbis -aq $quality_vorbis"
-_oggenc_vorbis="-q $quality_vorbis"
-_melt_opus="$_melt_audio acodec=libopus${channels:+ ab=$(($channels*$bitrate_opus))k}${opusapp:+ application=$opusapp}"
-_avconv_opus="-c:a libopus${channels:+ -b:a $(($channels*$bitrate_opus))k}${opusapp:+ -application $opusapp}"
-_opusenc_opus="${channels:+--bitrate $((channels*bitrate_opus))}"
-_melt_aac="$_melt_audio acodec=aac${channels:+ ab=$(($channels*$bitrate_aac))k}"
+_melt_vorbis="$_melt_downmix acodec=libvorbis aq=$quality_vorbis"
+_avconv_vorbis="$_avconv_downmix -c:a libvorbis -aq $quality_vorbis"
+_oggenc_vorbis="$_oggenc_downmix -q $quality_vorbis"
+_melt_opus="$_melt_downmix acodec=libopus${channels:+ ab=$(($channels*$bitrate_opus))k}${opusapp:+ application=$opusapp}"
+_avconv_opus="$_avconv_downmix -c:a libopus${channels:+ -b:a $(($channels*$bitrate_opus))k}${opusapp:+ -application $opusapp}"
+_opusenc_opus="$_opusenc_downmix ${channels:+--bitrate $((channels*bitrate_opus))}"
+_melt_aac="$_melt_downmix acodec=aac${channels:+ ab=$(($channels*$bitrate_aac))k}"
# container options
_melt_yuv4mpeg2="f=yuv4mpegpipe $_melt_video pix_fmt=yuv420p an=1 audio_off=1"
_avconv_yuv4mpeg2_in="-f yuv4mpegpipe"
_avconv_rawvideo="-f rawvideo"
-_melt_wav="f=wav $_melt_audio vn=1 video_off=1"
-_avconv_wav_in="-f wav $_avconv_audio"
+_melt_wav="f=wav $_melt_downmix vn=1 video_off=1"
+_avconv_wav_in="-f wav"
_oggenc_wav_in=
_opusenc_wav_in=
_melt_ogg="f=ogg $_melt_video $_melt_theora $_melt_vorbis"
@@ -450,7 +475,7 @@ if [ -n "$multipass" ] && [ -n "$webm$vp9" ]; then
$melt ${_melt_sample:-$infiles} \
${do_loudness:+$audioprefilters -filter loudness} \
$filters \
- ${do_loudness:+-consumer xml:$stem.xml $_melt_audio video_off=1 all=1} \
+ ${do_loudness:+-consumer xml:$stem.xml video_off=1 all=1} \
-consumer avformat:pipe:1 $_melt_yuv4mpeg2 \
| pee \
${webm:+"$vpxenc - $_vpxenc_vp8 -p 2 --pass=1 --fpf=${stem}_vp8.log -o /dev/null"} \
@@ -459,7 +484,7 @@ if [ -n "$multipass" ] && [ -n "$webm$vp9" ]; then
$melt ${_melt_sample:-$infiles} \
${do_loudness:+$audioprefilters -filter loudness} \
$filters \
- ${do_loudness:+-consumer xml:$stem.xml $_melt_audio video_off=1 all=1} \
+ ${do_loudness:+-consumer xml:$stem.xml video_off=1 all=1} \
-consumer avformat:pipe:1 $_melt_yuv4mpeg2 \
| $avconv $_avconv_yuv4mpeg2_in -i pipe:0 \
${webm:+$_avconv_rawvideo $_avconv_vp8 -an -pass 1 -passlogfile ${stem}_vp8 /dev/null} \