summaryrefslogtreecommitdiff
path: root/localvideowebencode
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2021-02-09 17:00:44 +0100
committerJonas Smedegaard <dr@jones.dk>2021-02-09 17:00:44 +0100
commit7cd9ec6b3131a7aa3efccdb7b85f1d2e883f35e3 (patch)
treedd4c6a9ba3e2f6fc50f1d34462ad206dc7a9d628 /localvideowebencode
parent0b77990c28752c959e6e9ef68887b516e923e932 (diff)
fix support theora
Diffstat (limited to 'localvideowebencode')
-rwxr-xr-xlocalvideowebencode63
1 files changed, 45 insertions, 18 deletions
diff --git a/localvideowebencode b/localvideowebencode
index d7ee157..624e895 100755
--- a/localvideowebencode
+++ b/localvideowebencode
@@ -250,9 +250,11 @@ infile_first=$(perl -e 'print shift @ARGV' $infiles)
stem=${stem:-$(basename "$infile_first" | perl -pe 's/\.[^.]*//')}
title=${title:-$stem}
+#use_ffmpeg_theora=yes
#use_ffmpeg_vp8=yes
#use_ffmpeg_vp9=yes
#use_ffmpeg_avc=yes
+#use_ffmpeg2theora=yes # TODO...
#use_vpxenc=yes
# Avoid discrete audio encoders if possible: may cause sync problems
#use_oggenc=yes
@@ -267,6 +269,7 @@ title=${title:-$stem}
[ -n "$use_lame_cbr" ] || use_lame_abr=yes
# resolve quality/speed hints
+qkey_theora=q
qkey_vp8=crf
qkey_vp9=crf
qkey_avc=crf
@@ -291,6 +294,7 @@ case "$compression" in
;;
hq)
multipass=yes
+ no_multipass_theora=yes # TODO: try with ffmpeg2theora
no_multipass_avc=yes
q_theora=6
cpu_vp8=0
@@ -317,7 +321,7 @@ if [ auto = "$gpu" ]; then
case "$vainfo" in
'') gpu=;;
*)
- for vformat in vp8 vp9 avc; do
+ for vformat in theora vp8 vp9 avc; do
eval "no_gpu_decoder_$vformat=yes"
eval "no_gpu_encoder_$vformat=yes"
done
@@ -569,7 +573,7 @@ fi
encoder_vp8=libvpx
encoder_vp9=libvpx-vp9
encoder_avc=libx264
-for vformat in vp8 vp9 avc; do
+for vformat in theora vp8 vp9 avc; do
[ -z "$no_bitrate" ] || eval "no_bitrate_$vformat=yes"
eval "[ -n \"$no_bitrate\$no_bitrate_$vformat\" ] || do_bitrate_$vformat=yes"
eval "[ -z \"$no_q\$no_q_$vformat\" ] || q_$vformat="
@@ -580,7 +584,7 @@ for vformat in vp8 vp9 avc; do
[ -z "$multipass" ] || eval "[ -n \"\$no_multipass_$vformat\" ] || multipass_$vformat=yes"
eval "[ -n \"\$multipass_$vformat\" ] || singlepass_$vformat=yes"
done
-if [ -n "$use_ffmpeg_vp8$use_ffmpeg_vp9$use_vpxenc" ]; then
+if [ -n "$use_ffmpeg_theora$use_ffmpeg_vp8$use_ffmpeg_vp9$use_vpxenc" ]; then
[ -n "$use_oggenc" ] || use_ffmpeg_vorbis=yes
[ -n "$use_opusenc" ] || use_ffmpeg_opus=yes
[ -z "$use_oggenc$use_opusenc" ] || use_wav=yes
@@ -591,12 +595,12 @@ if [ -n "$use_ffmpeg_avc" ]; then
else
use_melt_avc=yes
fi
-use_melt_any="${webm:+$use_melt_vp8}${webm_vp9:+$use_melt_vp9}${mp4:+$use_melt_avc}"
-use_ffmpeg_any="${webm:+$use_ffmpeg_vp8}${webm_vp9:+$use_ffmpeg_vp9}${mp4:+$use_ffmpeg_avc}"
+use_melt_any="${ogv:+$use_melt_theora}${webm:+$use_melt_vp8}${webm_vp9:+$use_melt_vp9}${mp4:+$use_melt_avc}"
+use_ffmpeg_any="${ogv:+$use_ffmpeg_theora}${webm:+$use_ffmpeg_vp8}${webm_vp9:+$use_ffmpeg_vp9}${mp4:+$use_ffmpeg_avc}"
use_vpxenc_any="${webm:+$use_vpxenc}${webm_vp9:+$use_vpxenc}"
use_opusenc_any="${webm:+$use_oggenc}${webm_vp9:+$use_opusenc}"
-use_oggenc_any="${webm:+$use_oggenc}${webm_vp9:+$use_opusenc}"
-[ -n "$use_ffmpeg_any$use_vpxenc_any" } || use_any_nomelt_video=yes
+use_oggenc_any="${ogv:+$use_oggenc}${webm:+$use_oggenc}${webm_vp9:+$use_opusenc}"
+[ -z "$use_ffmpeg_any$use_vpxenc_any" ] || use_any_nomelt_video=yes
[ -z "$gpu" ] || echo >&2 "GPU platform enabled: $gpu"
@@ -659,6 +663,8 @@ _opusenc_downmix="${downmix_opusenc:+${stereo:+--downmix-stereo}${mono:+--downmi
_melt_postfilters_audio="${limit:+-filter ladspa.1077}"
# format bitrate options
+_melt_bitrate_theora="${do_bitrate_theora:+ vb=$bitrate_theora}"
+_ffmpeg_bitrate_theora="${do_bitrate_theora:+ -b:v $bitrate_theora}"
_melt_bitrate_vp8="${do_bitrate_vp8:+ vb=$bitrate_vp8 minrate=$((bitrate_vp8/20)) maxrate=$((bitrate_vp8*12))}"
_ffmpeg_bitrate_vp8="${do_bitrate_vp8:+ -b:v $bitrate_vp8 -minrate $((bitrate_vp8/20)) -maxrate $((bitrate_vp8*12))}"
_vpxenc_bitrate_vp8="${do_bitrate_vp8:+ --target-bitrate=$((bitrate_vp8/1000))${multipass_vp8:+ --minsection-pct=5 --maxsection-pct=1200}}"
@@ -680,7 +686,8 @@ _ffmpeg_misc_avc="${no_gpu:+ -movflags +faststart}"
# format options
# emulate VP8 Constant Quality using "loose" Constrained Quality
-_melt_theora="vcodec=libtheora${bitrate_theora:+ vb=$bitrate_theora} qscale=$q_theora"
+_melt_theora="vcodec=libtheora$_melt_bitrate_theora $qkey_theora=$q_theora"
+_ffmpeg_theora="-c:v libtheora$_ffmpeg_bitrate_theora -$qkey_theora:v $q_theora"
_melt_vp8="vcodec=$encoder_vp8${pre_vp8:+ vpreset=$pre_vp8}${preset_vp8:+ preset=$preset_vp8}$_melt_bitrate_vp8${q_vp8:+ ${no_bitrate_vp8:+vb=$((bitrate_vp8*10)) }$qkey_vp8=$q_vp8}$_melt_misc_vp8"
_ffmpeg_vp8="-c:v $encoder_vp8${pre_vp8:+ -vpre $pre_vp8}${preset_vp8:+ preset $preset_vp8}$_ffmpeg_bitrate_vp8${q_vp8:+ ${no_bitrate_vp8:+-b:v $((bitrate_vp8*10)) }-$qkey_vp8 $q_vp8}$_ffmpeg_misc_vp8"
_vpxenc_vp8="--codec=vp8$_vpxenc_bitrate_vp8 --end-usage=${no_q_vp8:+vbr}${q_vp8:+cq --cq-level=$q_vp8}$_vpxenc_misc_vp8"
@@ -712,7 +719,11 @@ _opusenc_wav_in=
_melt_matroska_pcm="f=matroska $_melt_downmix $_melt_pcm vn=1 video_off=1"
_ffmpeg_matroska_pcm_in="-f matroska"
_melt_ogv="f=ogg $_melt_video $_melt_theora ${silence:+an=1 audio_off=1}${channels:+$_melt_vorbis}"
+_ffmpeg_ogv="-f ogg $_ffmpeg_video $_ffmpeg_theora ${silence:+-an}${channels:+ $_ffmpeg_vorbis}"
+_ffmpeg_ogv_in="-f ogg"
+_ffmpeg_ogv_keepvideo="-f ogg $_ffmpeg_video -c:v copy ${silence:+-an}${channels:+$_ffmpeg_vorbis}"
_ffmpeg_ogg_in="-f ogg"
+_ffmpeg_ogv_onlyvideo="-f ogg $_ffmpeg_video $_ffmpeg_theora -an"
_ffmpeg_ogg_vorbis="-f ogg -vn $_ffmpeg_vorbis"
_ffmpeg_ogg_opus="-f ogg -vn $_ffmpeg_opus"
_melt_webm="f=webm $_melt_video $_melt_vp8 ${silence:+an=1 audio_off=1}${channels:+$_melt_vorbis}"
@@ -743,7 +754,7 @@ if [ -n "$loudness" ] && [ -z "$silence$_melt_loudness" ]; then
echo >&2 "Loudness data: $_melt_loudness"
fi
-if [ -n "${webm:+$multipass_vp8}${webm_vp9:+$multipass_vp9}${mp4:+$multipass_avc}" ]; then
+if [ -n "${ogv:+$multipass_theora}${webm:+$multipass_vp8}${webm_vp9:+$multipass_vp9}${mp4:+$multipass_avc}" ]; then
echo >&2 "Analyzing video complexity..."
render melt $_melt_infiles $filters \
${webm:+${use_melt_vp8:+-consumer avformat:$stem.webm $_melt_webm \
@@ -754,7 +765,9 @@ if [ -n "${webm:+$multipass_vp8}${webm_vp9:+$multipass_vp9}${mp4:+$multipass_avc
pass=1 passlogfile=${stem}_avc}} \
${use_any_nomelt_video:+$_melt_stdout} \
| pee \
- ${any_ffmpeg:+"$(render ffmpeg-chained-echo $_ffmpeg_stdin \
+ ${use_ffmpeg_any:+"$(render ffmpeg-chained-echo $_ffmpeg_stdin \
+ ${ogv:+${use_ffmpeg_theora:+$_ffmpeg_rawvideo $_ffmpeg_ogv -an \
+ -pass 1 -passlogfile ${stem}_theora /dev/null}} \
${webm:+${use_ffmpeg_vp8:+$_ffmpeg_rawvideo $_ffmpeg_vp8 -an \
-pass 1 -passlogfile ${stem}_vp8 /dev/null}} \
${webm_vp9:+${use_ffmpeg_vp9:+$_ffmpeg_rawvideo $_ffmpeg_vp9 -an \
@@ -773,7 +786,8 @@ render melt $_melt_infiles \
${_melt_loudness:+-filter loudness program=$lufs \
results="$_melt_loudness"}} \
$filters${channels:+ $_melt_postfilters_audio} \
- ${ogv:+${use_melt_theora:+-consumer avformat:$stem.ogv $_melt_ogv}} \
+ ${ogv:+${use_melt_theora:+-consumer avformat:$stem.ogv $_melt_ogv \
+ ${multipass_theora:+pass=2 passlogfile=${stem}_theora}}} \
${webm:+${use_melt_vp8:+-consumer avformat:$stem.webm $_melt_webm \
${multipass_vp8:+pass=2 passlogfile=${stem}_vp8}}} \
${webm_vp9:+${use_melt_vp9:+-consumer avformat:${stem}_vp9.webm $_melt_webm_vp9 \
@@ -786,7 +800,10 @@ render melt $_melt_infiles \
$_melt_matroska_pcm}} \
${use_any_nomelt_video:+$_melt_stdout} \
| pee \
- ${any_ffmpeg:+"$(render ffmpeg-chained-echo $_ffmpeg_stdin \
+ ${use_ffmpeg_any:+"$(render ffmpeg-chained-echo $_ffmpeg_stdin \
+ ${ogv:+${use_ffmpeg_theora:+$_ffmpeg_ogv_onlyvideo \
+ ${multipass_theora:+-pass 2 -passlogfile ${stem}_theora} \
+ ${stem}${channels:+_silent}.ogv}} \
${webm:+${use_ffmpeg_vp8:+$_ffmpeg_webm_onlyvideo \
${multipass_vp8:+-pass 2 -passlogfile ${stem}_vp8} \
${stem}${channels:+_silent}.webm}} \
@@ -802,15 +819,25 @@ render melt $_melt_infiles \
${webm_vp9:+${use_vpxenc:+"$(render vpxenc-chained-echo - $_vpxenc_vp9 \
${multipass_vp9:+--pass=2 --fpf=${stem}_vp9.log} \
-o ${stem}_vp9${channels:+_silent}.webm)"}}
-if [ -n "${webm:+$use_vpxenc$use_oggenc}" ] && [ -n "$channels" ]; then
- echo >&2 "Encoding Vorbis audio and muxing with VP8 video..."
+if [ -n "${ogv:+$use_oggenc$use_ffmpeg_theora}${webm:+$use_vpxenc$use_oggenc}" ] && [ -n "$channels" ]; then
+ echo >&2 "Encoding Vorbis audio and muxing with video..."
+ # TODO: Encode once, muxing to containers as needed
if [ -n "$use_oggenc" ]; then
render oggenc $_oggenc_wav_in $_oggenc_vorbis -o - $stem.wav \
| render ffmpeg-chained \
- $_ffmpeg_webm_in -i ${stem}_silent.webm \
- $_ffmpeg_ogg_in -i pipe:0 \
- $_ffmpeg_webm_keepvideo $stem.webm
- else
+ ${ogv:+${use_oggenc:+$_ffmpeg_ogv_in -i ${stem}_silent.ogv \
+ $_ffmpeg_ogg_in -i pipe:0 \
+ $_ffmpeg_ogv_keepvideo $stem.ogv}} \
+ ${webm:+${use_oggenc:+$_ffmpeg_webm_in -i ${stem}_silent.webm \
+ $_ffmpeg_ogg_in -i pipe:0 \
+ $_ffmpeg_webm_keepvideo $stem.webm}}
+ fi
+ if [ -n "${ogv:+$use_ffmpeg_theora}" ]; then
+ render ffmpeg $_ffmpeg_ogv_in -i ${stem}_silent.ogv \
+ $_ffmpeg_matroska_wav_in -i $stem.mkv \
+ $_ffmpeg_ogv_keepvideo ${stem}.ogv
+ fi
+ if [ -n "${webm:+$use_vpxenc}" ]; then
render ffmpeg $_ffmpeg_webm_in -i ${stem}_silent.webm \
$_ffmpeg_matroska_wav_in -i $stem.mkv \
$_ffmpeg_webm_keepvideo ${stem}.webm