diff options
author | Jonas Smedegaard <dr@jones.dk> | 2021-02-08 13:19:19 +0100 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2021-02-08 21:47:31 +0100 |
commit | a3ed6a0fdf3a706055b737beef59f350df78af92 (patch) | |
tree | be803817f71c28756db2b805cf983010391d14c1 /localvideowebencode | |
parent | 51dd477d9a839e86f5363e57f7d1e8e2231885ce (diff) |
pass all render commands via function render()
Diffstat (limited to 'localvideowebencode')
-rwxr-xr-x | localvideowebencode | 88 |
1 files changed, 58 insertions, 30 deletions
diff --git a/localvideowebencode b/localvideowebencode index 5060645..58a099a 100755 --- a/localvideowebencode +++ b/localvideowebencode @@ -611,15 +611,43 @@ _ffmpeg_gpu_qsv_filter="-vf 'hwupload=extra_hw_frames=64,format=qsv'" _ffmpeg_gpu_filter="${gpu_vaapi:+ ${_ffmpeg_gpu_vaapi_filter}}${gpu_qsv:+ ${_ffmpeg_gpu_qsv_filter}}" # generic options -melt="melt -progress$_melt_gpu_init" which ffmpeg > /dev/null && ffmpeg=ffmpeg || ffmpeg=avconv -ffmpeg_alone="$ffmpeg -threads auto -y -hide_banner -v info -stats$_ffmpeg_gpu_init" -ffmpeg_chained="$ffmpeg -threads auto -y -v warning$_ffmpeg_gpu_init" -vpxenc_chained="vpxenc --quiet ${processors:+-t $((processors-1))}" -oggenc="oggenc" -opusenc="opusenc" _melt_infiles="${notsample:+$infiles}${sample:+$infile_first in=$((samplestart)) out=$((samplestart + samplelength))}" +render() { + engine=$1; shift + chained= + echo= + unchained=yes + case "$engine" in + ffmpeg-chained) engine=ffmpeg; chained=yes;; + vpxenc-chained) engine=vpxenc; chained=yes;; + ffmpeg-chained-echo) engine=ffmpeg; chained=yes; echo=yes;; + vpxenc-chained-echo) engine=vpxenc; chained=yes; echo=yes;; + esac + [ -z "$chained" ] || unchained= + case "$engine" in + melt) + set -- -progress$_melt_gpu_init "$@" + ;; + ffmpeg) + engine=$ffmpeg + set -- -threads auto -y -hide_banner -v ${unchained:+info -stats}${chained:+warning}$_ffmpeg_gpu_init "$@" + ;; + vpxenc) + set -- --quiet ${processors:+-t $((processors-1))} "$@" + ;; + oggenc) + set -- "$@" + ;; + opusenc) + set -- "$@" + ;; + *) exit1 "Unknown render engine \"$engine\".";; + esac + ${echo:+echo }"$engine" "$@" +} + # 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}" _ffmpeg_video="${no_gpu:+${do_deinterlace:+-filter:v yadif}${framerate:+ -r $framerate_num/$framerate_den}${size:+ -s ${width:+$width}x${height:+$height}}${aspect:+ -aspect $aspect}}" @@ -707,7 +735,7 @@ _melt_img="f=image2 $_melt_video" _melt_loudness="$loudness_data" if [ -n "$loudness" ] && [ -z "$silence$_melt_loudness" ]; then echo >&2 "Analyzing audio dynamics..." - $melt $_melt_infiles \ + render melt $_melt_infiles \ $audioprefilters -filter loudness $filters \ -consumer xml:$stem.xml video_off=1 all=1 _melt_loudness="$(perl -n \ @@ -718,7 +746,7 @@ fi if [ -n "${webm:+$multipass_vp8}${webm_vp9:+$multipass_vp9}${mp4:+$multipass_avc}" ]; then echo >&2 "Analyzing video complexity..." - $melt $_melt_infiles $filters $_melt_stdout \ + render melt $_melt_infiles $filters $_melt_stdout \ ${webm:+${use_melt_vp8:+-consumer avformat:$stem.webm $_melt_webm \ pass=1 passlogfile=${stem}_vp8}} \ ${webm_vp9:+${use_melt_vp9:+-consumer avformat:${stem}_vp9.webm $_melt_webm_vp9 \ @@ -726,21 +754,21 @@ if [ -n "${webm:+$multipass_vp8}${webm_vp9:+$multipass_vp9}${mp4:+$multipass_avc ${mp4:+${use_melt_avc:+-consumer avformat:$stem.mp4 $_melt_mp4 \ pass=1 passlogfile=${stem}_vp8}} \ | pee \ - ${any_ffmpeg:+"$ffmpeg_chained $_ffmpeg_stdin \ + ${any_ffmpeg:+"$(render ffmpeg-chained-echo $_ffmpeg_stdin \ ${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 \ -pass 1 -passlogfile ${stem}_vp9 /dev/null}} \ ${mp4:+${use_ffmpeg_avc:+$_ffmpeg_rawvideo $_ffmpeg_avc -an \ - -pass 1 -passlogfile ${stem}_avc /dev/null}}"} \ - ${webm:+${use_vpxenc:+"$vpxenc_chained - $_vpxenc_vp8 \ - --pass=1 --fpf=${stem}_vp8.log -o /dev/null"}} \ - ${webm_vp9:+${use_vpxenc:+"$vpxenc_chained - $_vpxenc_vp9 \ - --pass=1 --fpf=${stem}_vp9.log -o /dev/null"}} + -pass 1 -passlogfile ${stem}_avc /dev/null}})"} \ + ${webm:+${use_vpxenc:+"$(render vpxenc-chained-echo - $_vpxenc_vp8 \ + --pass=1 --fpf=${stem}_vp8.log -o /dev/null)"}} \ + ${webm_vp9:+${use_vpxenc:+"$(render vpxenc-chained-echo - $_vpxenc_vp9 \ + --pass=1 --fpf=${stem}_vp9.log -o /dev/null)"}} fi echo >&2 "Encoding video${channels:+ and audio}..." - $melt $_melt_infiles \ + render melt $_melt_infiles \ ${channels:+$audioprefilters \ ${_melt_loudness:+-filter loudness program=$lufs \ results="$_melt_loudness"}} \ @@ -758,7 +786,7 @@ fi $_melt_matroska_pcm}} \ $_melt_stdout \ | pee \ - ${any_ffmpeg:+"$ffmpeg_chained $_ffmpeg_stdin \ + ${any_ffmpeg:+"$(render ffmpeg-chained-echo $_ffmpeg_stdin \ ${webm:+${use_ffmpeg_vp8:+$_ffmpeg_webm_onlyvideo \ ${multipass_vp8:+-pass 2 -passlogfile ${stem}_vp8} \ ${stem}${channels:+_silent}.webm}} \ @@ -767,23 +795,23 @@ fi ${stem}_vp9${channels:+_silent}.webm}} \ ${mp4:+${use_ffmpeg_avc:+$_ffmpeg_mp4_onlyvideo \ ${multipass_avc:+-pass 2 -passlogfile ${stem}_avc} \ - ${stem}${channels:+_silent}.mp4}}"} \ - ${webm:+${use_vpxenc:+"$vpxenc_chained - $_vpxenc_vp8 \ + ${stem}${channels:+_silent}.mp4}})"} \ + ${webm:+${use_vpxenc:+"$(render vpxenc-chained-echo - $_vpxenc_vp8 \ ${multipass_vp8:+--pass=2 --fpf=${stem}_vp8.log} \ - -o ${stem}${channels:+_silent}.webm"}} \ - ${webm_vp9:+${use_vpxenc:+"$vpxenc_chained - $_vpxenc_vp9 \ + -o ${stem}${channels:+_silent}.webm)"}} \ + ${webm_vp9:+${use_vpxenc:+"$(render vpxenc-chained-echo - $_vpxenc_vp9 \ ${multipass_vp9:+--pass=2 --fpf=${stem}_vp9.log} \ - -o ${stem}_vp9${channels:+_silent}.webm"}} + -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 "$use_oggenc" ]; then - $oggenc $_oggenc_wav_in $_oggenc_vorbis -o - $stem.wav \ - | $ffmpeg_chained \ + 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 - $ffmpeg_alone $_ffmpeg_webm_in -i ${stem}_silent.webm \ + render ffmpeg $_ffmpeg_webm_in -i ${stem}_silent.webm \ $_ffmpeg_matroska_wav_in -i $stem.mkv \ $_ffmpeg_webm_keepvideo ${stem}.webm fi @@ -791,13 +819,13 @@ fi if [ -n "${webm_vp9:+$use_vpxenc$use_opusenc}" ] && [ -n "$channels" ]; then echo >&2 "Encoding Opus audio and muxing with VP9 video..." if [ -n "$use_opusenc" ]; then - $opusenc $_opusenc_wav_in $_opusenc_opus -o - $stem.wav \ - | $ffmpeg_chained \ + render opusenc $_opusenc_wav_in $_opusenc_opus -o - $stem.wav \ + | render ffmpeg-chained \ $_ffmpeg_webm_in -i ${stem}_vp9_silent.webm \ $_ffmpeg_ogg_in -i pipe:0 \ $_ffmpeg_webm_keepvideo_opus ${stem}_vp9.webm else - $ffmpeg_alone $_ffmpeg_webm_in -i ${stem}_vp9_silent.webm \ + render ffmpeg $_ffmpeg_webm_in -i ${stem}_vp9_silent.webm \ $_ffmpeg_matroska_wav_in -i $stem.mkv \ $_ffmpeg_webm_keepvideo_opus ${stem}_vp9.webm fi @@ -805,12 +833,12 @@ fi if [ -n "${mp4:+$use_ffmpeg_avc}" ] && [ -n "$channels" ]; then if [ -n "$use_mp3" ]; then echo "Encoding MP3 audio and muxing with H.264/AVC video..." - $ffmpeg_alone $_ffmpeg_mp4_in -i ${stem}_silent.mp4 \ + render ffmpeg $_ffmpeg_mp4_in -i ${stem}_silent.mp4 \ $_ffmpeg_matroska_wav_in -i $stem.mkv \ $_ffmpeg_mp4_keepvideo ${stem}.mp4 else echo "Encoding AAC audio and muxing with H.264/AVC video..." - $ffmpeg_alone $_ffmpeg_mp4_in -i ${stem}_silent.mp4 \ + render ffmpeg $_ffmpeg_mp4_in -i ${stem}_silent.mp4 \ $_ffmpeg_matroska_wav_in -i $stem.mkv \ $_ffmpeg_mp4_keepvideo_aac ${stem}.mp4 fi @@ -820,7 +848,7 @@ fi rm -f $stem.xml $stem.wav $stem.mkv ${stem}_*.log ${stem}_*silent.webm # JPEG preview -$melt $infile_first in=$stillframe out=$stillframe \ +render melt $infile_first in=$stillframe out=$stillframe \ -group $filters \ -consumer avformat:$stem.jpg $_melt_img |