pv-test, another large refactor which allows typing custom tests in while keeping some loops as questions, enhanced output and the handling of loop indentation, use more -n checks to avoid whitespace issues.

This commit is contained in:
me
2026-09-14 15:52:03 -07:00
parent 7463e4a9b8
commit da0be0ab41
+173 -118
View File
@@ -788,47 +788,14 @@ function pv-test {
if [[ $normalize_in != "N"* && $normalize_in != "F"* ]]; then if [[ $normalize_in != "N"* && $normalize_in != "F"* ]]; then
normalize="-filter:a dynaudnorm=f=33:g=65:p=0.66:m=33.3" normalize="-filter:a dynaudnorm=f=33:g=65:p=0.66:m=33.3"
fi fi
echo " normalize: '$normalize'" echo " normalize: '$normalize'"
typeset -i size_in typeset -i size_in
read -p "What display ratio would you like to use? (720) " size_in read -p "What display ratio would you like to use? (720) " size_in
if (( $size_in == 0 )); then if (( $size_in == 0 )); then
size_in=720 size_in=720
fi fi
echo " size: '$size_in'" echo " size: '$size_in'"
# Loop Data #
echo "Setting some defaults..."
vcodecs="libx264 libsvtav1 libx265" && echo " video codecs: '$vcodecs'"
acodecs="aac libopus" && echo " audio codecs: '$acodecs'"
exts="mkv" && echo " extensions: '$exts'" # mp4
declare -l {vpreset,crf,vbr,abr}s="skip"
read -p "Test presets? (y/N) " test_vpresets
if [[ "$test_vpresets" == "y"* ]]; then
vpresets="$vpresets slw med fst"
fi
echo " presets: '$vpresets'"
read -p "Test CRFs? (y/N) " test_crfs
if [[ "$test_crfs" == "y"* ]]; then
crfs="$crfs 24 26 28 30 32"
fi
echo " CRFs: '$crfs'"
read -p "Test video bitrates? (y/N) " test_vbrs
if [[ "$test_vbrs" == "y"* ]]; then
vbrs="$vbrs 1500k 2000k 2500k"
fi
echo " video bitrates: '$vbrs'"
read -p "Test audio bitrates? (y/N) " test_abrs
if [[ "$test_abrs" == "y"* ]]; then
abrs="$abrs 128k 192k"
fi
echo " audio bitrates: '$abrs'"
# Existing Functions # # Existing Functions #
@@ -838,25 +805,99 @@ function pv-test {
read -p "Create a test with current 'pv' function? (Y/n) " test_pv read -p "Create a test with current 'pv' function? (Y/n) " test_pv
if [[ -z "$test_pv" || "$test_pv" == "y"* ]]; then if [[ -z "$test_pv" || "$test_pv" == "y"* ]]; then
pv="y" pv="y"
echo " great, will run pv" echo " great, will run pv"
else else
echo " skipping" echo " skipping"
fi fi
read -p "Create a test with current 'pv2' function? (Y/n) " test_pv2 read -p "Create a test with current 'pv2' function? (Y/n) " test_pv2
if [[ -z "$test_pv2" || "$test_pv2" == "y"* ]]; then if [[ -z "$test_pv2" || "$test_pv2" == "y"* ]]; then
pv2="y" pv2="y"
echo " great, will run pv2" echo " great, will run pv2"
else else
echo " skipping" echo " skipping"
fi fi
# Loop Data #
declare -l {vpreset,crf,vbr,abr,achannel,afreq}s="default"
echo -e "\n * * Loop Settings * * \n"
vcodecs="libx264"
read -p "Video codec libx264 always enabled, add testing of libx265 and libsvtav1? (Y/n) " test_vcodecs
if [[ -z "$test_vcodecs" || "$test_vcodecs" == "y"* ]]; then
vcodecs="$vcodecs libsvtav1 libx265"
fi
read -p "Please provide any additional video codecs: " test_vcodecs
if [[ -n "$test_vcodecs" ]]; then
vcodecs="$vcodecs $test_vcodecs"
fi
echo " video codecs: '$vcodecs'"
read -p "Test the video codec's slowest, medium, fastest presets? (y/N) " test_vpresets
if [[ "$test_vpresets" == "y"* ]]; then
vpresets="slw med fst"
fi
echo " presets: '$vpresets'"
read -p "Please provide any CRFs to test: [default] " test_crfs
if [[ -n "$test_vcodecs" ]]; then
crfs="$test_crfs"
fi
echo " CRFs: '$crfs'"
read -p "Please provide any video bitrates to test: [default] " test_vbrs
if [[ -n "$test_vbrs" ]]; then
vbrs="$test_vbrs"
fi
echo " video bitrates: '$vbrs'"
echo " "
acodecs="aac"
read -p "Audio codec aac always enabled, add testing of libopus? (Y/n) " test_acodecs
if [[ -z "$test_acodecs" || "$test_acodecs" == "y"* ]]; then
acodecs="$acodecs libopus"
fi
read -p "Please provide any additional audio codecs: " test_acodecs
if [[ -n "$test_acodecs" ]]; then
acodecs="$acodecs $test_acodecs"
fi
echo " audio codecs: '$acodecs'"
read -p "Please provide any audio bitrates to test: [default] " test_abrs
if [[ -n "$test_abrs" ]]; then
abrs="$test_abrs"
fi
echo " audio bitrates: '$abrs'"
read -p "Test both mono and stereo audio channels? (y/N) " test_achannels
if [[ "$test_achannels" == "y"* ]]; then
achannels="1 2" # 1 is mono, 2 is stereo
fi
echo " audio channels: '$achannels'"
read -p "Test both 48 and 44.1 kHz audio frequencies? (y/N) " test_afreqs
if [[ "$test_afreqs" == "y"* ]]; then
afreqs="48000 44100" # 48 typically found in videos, 44.1 in audio.
fi
echo " audio frequencies: '$afreqs'"
read -p "Please provide any containers to test with: [mkv] " test_exts
if [[ -n "$test_exts" ]]; then
exts="$test_exts"
fi
echo " extensions: '$exts'"
# Final Check # # Final Check #
echo -e "\n * * Confirmation * * \n"
typeset -u okay typeset -u okay
echo -e "\nTesting all these using '$filename_in'" echo "Testing all these using '$filename_in'"
read -p "Does everything look okay? (Y/n) " okay read -p "Does everything look okay? (Y/n) " okay
if [[ "$okay" == "N" || "$okay" == "F"* ]]; then if [[ "$okay" == "N" || "$okay" == "F"* ]]; then
echo "* Not okay, aborting." echo " Not okay, aborting."
return 1 return 1
fi fi
echo -e "Sounds good, here we go!\n" echo -e "Sounds good, here we go!\n"
@@ -884,97 +925,111 @@ function pv-test {
echo -e "\nStarting the loop...\n" echo -e "\nStarting the loop...\n"
count=0
unset vcodec vpreset crf vbr acodec abr ext unset vcodec vpreset crf vbr acodec abr ext
for vcodec in $vcodecs; do for vcodec in $vcodecs; do for vpreset in $vpresets; do
for vpreset in $vpresets; do for crf in $crfs; do for vbr in $vbrs; do
for crf in $crfs; do for acodec in $acodecs; do for abr in $abrs;
for vbr in $vbrs; do do for achannel in $achannels; do for afreq in $afreqs; do
for acodec in $acodecs; do for ext in $exts; do
for abr in $abrs; do
for ext in $exts; do
preset="" preset=""
if [[ "$vpreset" != "skip" ]]; then if [[ "$vpreset" != "default" ]]; then
if [[ "$vcodec" == "libsvtav1" ]]; then if [[ "$vcodec" == "libsvtav1" ]]; then
case $vpreset in case $vpreset in
slw) preset="0" ;; slw) preset="0" ;;
med) preset="6" ;; med) preset="6" ;;
fst) preset="13" ;; fst) preset="13" ;;
*) echo "ERROR: Unhandled vpreset '${vpreset}', exiting." && return 1 *) echo "ERROR: Unhandled vpreset '${vpreset}', exiting." && return 1
esac esac
else else
case $vpreset in case $vpreset in
slw) preset="veryslow" ;; slw) preset="veryslow" ;;
med) preset="medium" ;; med) preset="medium" ;;
fst) preset="ultrafast" ;; fst) preset="ultrafast" ;;
*) echo "ERROR: Unhandled vpreset '${vpreset}', exiting" && return 1 *) echo "ERROR: Unhandled vpreset '${vpreset}', exiting" && return 1
esac esac
fi fi
if [[ -n "$preset" ]]; then if [[ -n "$preset" ]]; then
preset="-preset $preset" preset="-preset $preset"
fi fi
fi fi
bitrate="" bitrate=""
if [[ "$crf" != "skip" ]]; then if [[ "$crf" != "default" ]]; then
bitrate="-crf $crf" bitrate="-crf $crf"
fi fi
if [[ "$vbr" != "skip" ]]; then if [[ "$vbr" != "default" ]]; then
if [[ "$vcodec" == "libsvtav1" ]]; then if [[ "$vcodec" == "libsvtav1" ]]; then
bitrate="$bitrate -svtav1-params rc=1:tbr=$vbr:overshoot-pct=0:undershoot-pct=100" bitrate="$bitrate -svtav1-params rc=1:tbr=$vbr:overshoot-pct=0:undershoot-pct=100"
else else
bitrate="$bitrate -b:v $vbr -minrate 0 -maxrate $vbr -bufsize $vbr" bitrate="$bitrate -b:v $vbr -minrate 0 -maxrate $vbr -bufsize $vbr"
fi fi
fi fi
fidelity="" fidelity=""
if [[ "$abr" != "skip" ]]; then if [[ "$abr" != "default" ]]; then
fidelity="-b:a $abr" fidelity="-b:a $abr"
fi fi
newfile="_${size_in}p_${vcodec}-${vpreset}-${vbr}${crf}_${acodec}-${abr}.${ext}" channel=""
if [[ -e "$newfile" ]]; then if [[ "$achannel" != "default" ]]; then
mv -v "$newfile" ~/TRASH/ channel="-ac $achannel"
fi fi
echo -e "\n* Starting new run...\n" frequency=""
echo -e "Parameters for this run: $newfile\n" if [[ "$afreq" != "default" ]]; then
frequency="-ar $afreq"
fi
start=$SECONDS newfile="_${size_in}p_${vcodec}-${vpreset}-${crf}-${vbr}_${acodec}-${abr}-${achannel}-${afreq}.${ext}"
set -x if [[ -e "$newfile" ]]; then
ffmpeg -nostdin -hide_banner -loglevel level+warning \ mv -v "$newfile" ~/TRASH/
-i "$filename_in" \ fi
-filter:v scale=-1:$size_in \
-c:v $vcodec \
$preset \
$bitrate \
-c:a $acodec \
$fidelity \
$normalize \
-movflags +faststart \
"$newfile"
set +x
finish=$SECONDS
minutes=$(( (finish - start) / 60 )) echo -e "\n* Starting new run...\n"
seconds=$(( (finish - start) % 60 )) echo -e "Parameters for this run: $newfile\n"
printf -v padded_mins "%03d" "$minutes"
printf -v padded_secs "%02d" "$seconds"
mv -v "$newfile" "$(basename "${filename_in}_${padded_mins}m${padded_secs}s${newfile}")" start=$SECONDS
set -x
ffmpeg -nostdin -hide_banner -loglevel level+warning \
-i "$filename_in" \
-filter:v scale=-1:$size_in \
-c:v $vcodec \
$preset \
$bitrate \
-c:a $acodec \
$fidelity \
$channel \
$frequency \
$normalize \
-movflags +faststart \
"$newfile"
set +x
finish=$SECONDS
echo -e "\n* Finished in ${minutes}m${seconds}s!\n" minutes=$(( (finish - start) / 60 ))
done seconds=$(( (finish - start) % 60 ))
done printf -v padded_mins "%03d" "$minutes"
printf -v padded_secs "%02d" "$seconds"
mv -v "$newfile" "$(basename "${filename_in}_${padded_mins}m${padded_secs}s${newfile}")"
echo -e "\n* Finished in ${minutes}m${seconds}s!\n"
count=$(( count++ ))
done done
done done done
done done done
done done done
done done done
## Finish ## ## Finish ##
echo "Done! :)" plural=""
if (( $count != 1 )); then
plural="s"
fi
echo "Completed tests after ${count} loop${plural}! :)"
} }