pv-test, huge rework to allow much better dynamic testing rather than manually commenting for loops and changing values, added automated tests for pv and pv2.

This commit is contained in:
me
2026-09-14 10:22:30 -07:00
parent 3c01ed7331
commit f0e8125109
+148 -25
View File
@@ -771,77 +771,196 @@ alias vta="v2a"
alias pull-audio="v2a" alias pull-audio="v2a"
alias pa="v2a" alias pa="v2a"
# Run all the different codecs, wrappers, bitrates, etc on a file. # Run all the different codecs, wrappers, bitrates, etc on a file.
function pv-test { function pv-test {
## Input ##
filename_in="$1" filename_in="$1"
while [[ -z "$filename_in" ]]; do while [[ -z "$filename_in" ]]; do
read -p "Please provide the filename: " filename_in read -p "Please provide the filename: " filename_in
done done
# Persistent Data #
normalize="" normalize=""
typeset -u normalize_in typeset -u normalize_in
read -p "Would you like to normalize the audio? (Y/n) " normalize_in read -p "Would you like to normalize the audio? (Y/n) " normalize_in
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'"
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
echo "Size not set, assuming 720."
size_in=720 size_in=720
fi fi
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"
echo "$vpresets $crfs" #deleteme
read -p "Test presets? (y/N) " test_vpresets
if [[ "$test_vpresets" == "y"* ]]; then
vpresets="slo fst def" # med
fi
echo " presets: '$vpresets'"
read -p "Test CRFs? (y/N) " test_crfs
if [[ "$test_crfs" == "y"* ]]; then
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="1500k 2000k 2500k"
fi
echo " video bitrates: '$vbrs'"
read -p "Test audio bitrates? (y/N) " test_abrs
if [[ "$test_abrs" == "y"* ]]; then
abrs="128k 192k"
fi
echo " audio bitrates: '$abrs'"
# Existing Functions #
declare -l pv{,2}="n"
typeset -l test_pv{,2}
read -p "Create a test with current 'pv' function? (Y/n) " test_pv
if [[ -z "$test_pv" || "$test_pv" == "y"* ]]; then
pv="y"
echo " great, will do!"
else
echo " skipping"
fi
read -p "Create a test with current 'pv2' function? (Y/n) " test_pv2
if [[ -z "$test_pv2" || "$test_pv2" == "y"* ]]; then
pv2="y"
echo " great, will do!"
else
echo " skipping"
fi
# Final Check #
typeset -u okay typeset -u okay
echo "* Testing with '$filename_in'" echo " Testing all this with '$filename_in'"
echo "* Normalize set to '$normalize'"
echo "* Size set to '$size_in'"
read -p "Look okay? (Y/n) " okay read -p "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
for vcodec in libx264 libsvtav1 libx265; do ## Main ##
#echo "3 4 5" | while read vpreset; do
#echo "25 28 32" | while read crf; do echo -e "\nHere we go!\n"
for vbr in 2000k; do # 1500k 2000k 2500k
for acodec in aac libopus; do if [[ "$pv" == "y" ]]; then
for abr in 192k 128k; do echo "Starting pv..."
for ext in mkv; do # mp4 mkv filename_pv="${filename_in}-pv.mkv"
bitrate="" if [[ -e "$filename_pv" ]]; then
if [[ $vcodec == "libsvtav1" ]]; then mv -v "$filename_pv" ~/TRASH
bitrate="-svtav1-params rc=1:tbr=$vbr:overshoot-pct=0:undershoot-pct=100" fi
else pv "$filename_in" "$filename_pv"
bitrate="-b:v $vbr -minrate 0 -maxrate $vbr -bufsize $vbr" echo -e "Testing with 'pv' complete!\n"
fi
if [[ "$pv2" == "y" ]]; then
echo "Starting pv2..."
filename_pv2="${filename_in}-pv2.mkv"
if [[ -e "$filename_pv2" ]]; then
mv -v "$filename_pv2" ~/TRASH
fi
pv "$filename_in" "$filename_pv2"
echo -e "Testing with 'pv2' complete!\n"
fi fi
#newfile="_$vcodec-p$vpreset-$crf_$acodec-$abr.$ext" echo -e "\nStarting the loop...\n"
newfile="_${size_in}_${vcodec}-${vbr}_${acodec}-${abr}.${ext}"
start=$SECONDS unset vcodec vpreset crf vbr acodec abr ext
for vcodec in $vcodecs; do
for vpreset in $vpresets; do
for crf in $crfs; do
for vbr in $vbrs; do
for acodec in $acodecs; do
for abr in $abrs; do
for ext in $exts; do
preset=""
if [[ "$vpreset" != "skip" && "$vpreset" != "def" ]]; then
if [[ "$vcodec" == "libsvtav1" ]]; then
case $vpreset in
slo) preset="0" ;;
med) preset="6" ;;
fst) preset="13" ;;
esac
else
case $vpreset in
slo) preset="veryslow" ;;
med) preset="medium" ;;
fst) preset="ultrafast" ;;
esac
fi
if [[ -n "$preset" ]]; then
preset="-preset $preset"
fi
fi
bitrate=""
if [[ "$crf" != "skip" ]]; then
bitrate="-crf $crf"
fi
if [[ "$vbr" != "skip" ]]; then
if [[ "$vcodec" == "libsvtav1" ]]; then
bitrate="$bitrate -svtav1-params rc=1:tbr=$vbr:overshoot-pct=0:undershoot-pct=100"
else
bitrate="$bitrate -b:v $vbr -minrate 0 -maxrate $vbr -bufsize $vbr"
fi
fi
fidelity=""
if [[ "$abr" != "skip" ]]; then
fidelity="-b:a $abr"
fi
newfile="_${size_in}p_${vcodec}-${vpreset}-${vbr}${crf}_${acodec}-${abr}.${ext}"
if [[ -e "$newfile" ]]; then
mv -v "$newfile" ~/TRASH/
fi
echo -e "\n* Starting new run...\n" echo -e "\n* Starting new run...\n"
echo -e "Parameters for this run: $newfile\n" echo -e "Parameters for this run: $newfile\n"
start=$SECONDS
set -x set -x
# -preset $vpreset -crf $crf \
ffmpeg -nostdin -hide_banner -loglevel level+warning \ ffmpeg -nostdin -hide_banner -loglevel level+warning \
-i "$filename_in" \ -i "$filename_in" \
-filter:v scale=-1:$size_in \ -filter:v scale=-1:$size_in \
-c:v $vcodec \ -c:v $vcodec \
$preset \
$bitrate \ $bitrate \
-c:a $acodec \ -c:a $acodec \
-b:a $abr \ $fidelity \
$normalize \ $normalize \
-movflags +faststart \ -movflags +faststart \
"$newfile" "$newfile"
set +x set +x
finish=$SECONDS finish=$SECONDS
minutes=$(( (finish - start) / 60 )) minutes=$(( (finish - start) / 60 ))
seconds=$(( (finish - start) % 60 )) seconds=$(( (finish - start) % 60 ))
printf -v padded_mins "%03d" "$minutes" printf -v padded_mins "%03d" "$minutes"
printf -v padded_secs "%02d" "$seconds" printf -v padded_secs "%02d" "$seconds"
mv -v "$newfile" "${filename_in}_${padded_mins}m${padded_secs}s${newfile}" mv -v "$newfile" "${filename_in}_${padded_mins}m${padded_secs}s${newfile}"
echo -e "\n* Finished in ${minutes}m${seconds}s!\n" echo -e "\n* Finished in ${minutes}m${seconds}s!\n"
@@ -849,9 +968,13 @@ function pv-test {
done done
done done
done done
#done
#done
done done
done
done
## Finish ##
echo "Done! :)"
} }