From c24af2137afb3a15d92c084dea02418c8e77e7d6 Mon Sep 17 00:00:00 2001
From: Jonas Smedegaard <dr@jones.dk>
Date: Sun, 7 Feb 2021 21:00:45 +0100
Subject: tidy: separate bitrate and low-level options for avc

---
 localvideowebencode | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/localvideowebencode b/localvideowebencode
index 4254093..43f6d7d 100755
--- a/localvideowebencode
+++ b/localvideowebencode
@@ -633,6 +633,8 @@ _vpxenc_bitrate_vp8="--target-bitrate=$((bitrate_vp8/1000)) --minsection-pct=5 -
 _melt_bitrate_vp9="${do_bitrate_vp9:+ vb=$bitrate_vp9} minrate=$((bitrate_vp9/20)) maxrate=$((bitrate_vp9*12))"
 _ffmpeg_bitrate_vp9="${do_bitrate_vp9:+-b:v $bitrate_vp9} -minrate $((bitrate_vp9/20)) -maxrate $((bitrate_vp9*12))"
 _vpxenc_bitrate_vp9="--target-bitrate=$((bitrate_vp9/1000)) --minsection-pct=5 --maxsection-pct=1200"
+_melt_bitrate_avc="${do_bitrate_avc:+ maxrate=$bitrate_avc${no_gpu:+ bufsize=$((bitrate_avc*2))}}"
+_ffmpeg_bitrate_avc="${do_bitrate_avc:+ -maxrate $bitrate_avc${no_gpu:+ -bufsize $((bitrate_avc*2))}}"
 
 # format low-level options
 _melt_misc_vp8="qmin=$qmin_vp8 qmax=$qmax_vp8 g=120 deadline=good cpu-used=$cpu_vp8${profile_vp8:+ vprofile=$profile_vp8} auto-alt-ref=1 lag-in-frames=$lag_vp8 arnr-maxframes=7 arnr-strength=5 arnr-type=centered"
@@ -641,6 +643,8 @@ _vpxenc_misc_vp8="--min-q=$qmin_vp8 --max-q=$qmax_vp8 --kf-max-dist=120 --good -
 _melt_misc_vp9="qmin=$qmin_vp9 qmax=$qmax_vp9 g=120 deadline=good cpu-used=$cpu_vp9${profile_vp9:+ vprofile=$profile_vp9} auto-alt-ref=1 lag-in-frames=$lag_vp9 arnr-maxframes=7 arnr-strength=5 arnr-type=centered"
 _ffmpeg_misc_vp9="-qmin $qmin_vp9 -qmax $qmax_vp9 -g 120 -deadline good -cpu-used $cpu_vp9${profile_vp9:+ -profile:v $profile_vp9} -auto-alt-ref 1 -lag-in-frames $lag_vp9 -arnr-maxframes 7 -arnr-strength 5 -arnr-type centered"
 _vpxenc_misc_vp9="--min-q=$qmin_vp9 --max-q=$qmax_vp9 --kf-max-dist=120 --good --cpu-used=$cpu_vp9${profile_vp9:+ --profile=$profile_vp9} --tile-columns=$tokenparts_log2_vp9 --tile-rows=$tokenparts_log2_vp9 --auto-alt-ref=1 --lag-in-frames=$lag_vp9 --arnr-maxframes=7 --arnr-strength=5 --arnr-type=3"
+_melt_misc_avc="${no_gpu:+ movflags=+faststart}"
+_ffmpeg_misc_avc="${no_gpu:+ -movflags +faststart}"
 
 # format options
 # emulate VP8 Constant Quality using "loose" Constrained Quality
@@ -651,8 +655,8 @@ _vpxenc_vp8="--codec=vp8${do_bitrate_vp8:+ $_vpxenc_bitrate_vp8} --end-usage=${n
 _melt_vp9="vcodec=$encoder_vp9${pre_vp9:+ vpreset=$pre_vp9}${preset_vp9:+ preset=$preset_vp9}${do_bitrate_vp9:+ $_melt_bitrate_vp9}${q_vp9:+ ${no_bitrate_vp9:+vb=0 }$qkey_vp9=$q_vp9} $_melt_misc_vp9"
 _ffmpeg_vp9="-c:v $encoder_vp9${pre_vp9:+ -vpre $pre_vp9}${preset_vp9:+ -preset $preset_vp9}${do_bitrate_vp9:+ $_ffmpeg_bitrate_vp9}${q_vp9:+ ${no_bitrate_vp9:+-b:v 0 }-$qkey_vp9 $q_vp9} $_ffmpeg_misc_vp9"
 _vpxenc_vp9="--codec=vp9${do_bitrate_vp9:+ $_vpxenc_bitrate_vp9} --end-usage=${no_q_vp9:+vbr}${q_vp9:+cq --cq-level=$q_vp9} $_vpxenc_misc_vp9"
-_melt_avc="vcodec=$encoder_avc${preset_avc:+ vpreset=$preset_avc}${profile_avc:+ vprofile=$profile_avc}${x264tune:+ tune=$x264tune}${do_bitrate_avc:+ maxrate=$bitrate_avc${no_gpu:+ bufsize=$((bitrate_avc*2))}}${q_avc:+ $qkey_avc=$q_avc} threads=0${no_gpu:+ movflags=+faststart}"
-_ffmpeg_avc="-c:v $encoder_avc${preset_avc:+ -preset $preset_avc}${profile_avc:+ -profile:v $profile_avc}${x264tune:+ -tune $x264tune}${do_bitrate_avc:+ -maxrate $bitrate_avc${no_gpu:+ -bufsize $((bitrate_avc*2))}}${q_avc:+ -$qkey_avc $q_avc}${no_gpu:+ -movflags +faststart}"
+_melt_avc="vcodec=$encoder_avc${preset_avc:+ vpreset=$preset_avc}${profile_avc:+ vprofile=$profile_avc}${x264tune:+ tune=$x264tune}$_melt_bitrate_avc${q_avc:+ $qkey_avc=$q_avc} threads=0$_melt_misc_avc"
+_ffmpeg_avc="-c:v $encoder_avc${preset_avc:+ -preset $preset_avc}${profile_avc:+ -profile:v $profile_avc}${x264tune:+ -tune $x264tune}$_ffmpeg_bitrate_avc${q_avc:+ -$qkey_avc $q_avc}$_ffmpeg_misc_avc"
 _melt_pcm="$_melt_downmix acodec=pcm_s16le"
 _melt_vorbis="$_melt_downmix acodec=libvorbis aq=$quality_vorbis"
 _ffmpeg_vorbis="$_ffmpeg_downmix -c:a libvorbis -aq $quality_vorbis"
-- 
cgit v1.2.3