pv-test, continuing the usability and output enhancements. Now recognizes if an unfinished version needs re-done, if the finished test already exists, and checks ffmpeg status before committing the file.

This commit is contained in:
me
2026-09-14 16:42:49 -07:00
parent da0be0ab41
commit 701dfbcc96
+73 -45
View File
@@ -788,14 +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 -e " normalize: '$normalize'\n"
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 -e " size: '$size_in'\n"
# Existing Functions # # Existing Functions #
@@ -809,6 +809,7 @@ function pv-test {
else else
echo " skipping" echo " skipping"
fi fi
echo " "
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"
@@ -816,82 +817,74 @@ function pv-test {
else else
echo " skipping" echo " skipping"
fi fi
echo " "
# Loop Data # # Loop Data #
declare -l {vpreset,crf,vbr,abr,achannel,afreq}s="default" declare -l {vpreset,crf,vbr,abr,achannel,afreq}s="default"
echo -e "\n * * Loop Settings * * \n" echo -e " * * Loop Settings * * \n"
vcodecs="libx264" vcodecs="libx264 libsvtav1 libx265"
read -p "Video codec libx264 always enabled, add testing of libx265 and libsvtav1? (Y/n) " test_vcodecs read -p "Please provide the video codecs to test: [$vcodecs] " 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 if [[ -n "$test_vcodecs" ]]; then
vcodecs="$vcodecs $test_vcodecs" vcodecs="$test_vcodecs"
fi fi
echo " video codecs: '$vcodecs'" echo -e " video codecs: '$vcodecs'\n"
read -p "Test the video codec's slowest, medium, fastest presets? (y/N) " test_vpresets read -p "Test the video codec's slowest, medium, and fastest presets? (y/N) " test_vpresets
if [[ "$test_vpresets" == "y"* ]]; then if [[ "$test_vpresets" == "y"* ]]; then
vpresets="slw med fst" vpresets="slw med fst"
fi fi
echo " presets: '$vpresets'" echo -e " presets: '$vpresets'\n"
read -p "Please provide any CRFs to test: [default] " test_crfs read -p "Please provide any CRFs to test: [default] " test_crfs
if [[ -n "$test_vcodecs" ]]; then if [[ -n "$test_crfs" ]]; then
crfs="$test_crfs" crfs="$test_crfs"
fi fi
echo " CRFs: '$crfs'" echo -e " CRFs: '$crfs'\n"
read -p "Please provide any video bitrates to test: [default] " test_vbrs read -p "Please provide any video bitrates to test: [default] " test_vbrs
if [[ -n "$test_vbrs" ]]; then if [[ -n "$test_vbrs" ]]; then
vbrs="$test_vbrs" vbrs="$test_vbrs"
fi fi
echo " video bitrates: '$vbrs'" echo -e " video bitrates: '$vbrs'\n"
echo " " acodecs="aac libopus"
read -p "Please provide the audio codecs to test: [$acodecs] " test_acodecs
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 if [[ -n "$test_acodecs" ]]; then
acodecs="$acodecs $test_acodecs" acodecs="$test_acodecs"
fi fi
echo " audio codecs: '$acodecs'" echo -e " audio codecs: '$acodecs'\n"
read -p "Please provide any audio bitrates to test: [default] " test_abrs read -p "Please provide any audio bitrates to test: [default] " test_abrs
if [[ -n "$test_abrs" ]]; then if [[ -n "$test_abrs" ]]; then
abrs="$test_abrs" abrs="$test_abrs"
fi fi
echo " audio bitrates: '$abrs'" echo -e " audio bitrates: '$abrs'\n"
read -p "Test both mono and stereo audio channels? (y/N) " test_achannels read -p "Test both mono and stereo audio channels? (y/N) " test_achannels
if [[ "$test_achannels" == "y"* ]]; then if [[ "$test_achannels" == "y"* ]]; then
achannels="1 2" # 1 is mono, 2 is stereo achannels="1 2" # 1 is mono, 2 is stereo
fi fi
echo " audio channels: '$achannels'" echo -e " audio channels: '$achannels'\n"
read -p "Test both 48 and 44.1 kHz audio frequencies? (y/N) " test_afreqs read -p "Test both 48 and 44.1 kHz audio frequencies? (y/N) " test_afreqs
if [[ "$test_afreqs" == "y"* ]]; then if [[ "$test_afreqs" == "y"* ]]; then
afreqs="48000 44100" # 48 typically found in videos, 44.1 in audio. afreqs="48000 44100" # 48 typically found in videos, 44.1 in audio.
fi fi
echo " audio frequencies: '$afreqs'" echo -e " audio frequencies: '$afreqs'\n"
read -p "Please provide any containers to test with: [mkv] " test_exts exts="mkv"
read -p "Please provide the containers to test with: [$exts] " test_exts
if [[ -n "$test_exts" ]]; then if [[ -n "$test_exts" ]]; then
exts="$test_exts" exts="$test_exts"
fi fi
echo " extensions: '$exts'" echo -e " extensions: '$exts'\n"
# Final Check # # Final Check #
echo -e "\n * * Confirmation * * \n" echo -e " * * Confirmation * * \n"
typeset -u okay typeset -u okay
echo "Testing all these using '$filename_in'" echo "Testing all these using '$filename_in'"
@@ -905,25 +898,41 @@ function pv-test {
## Main ## ## Main ##
if [[ "$pv" == "y" ]]; then if [[ "$pv" == "y" ]]; then
echo "Starting pv..." echo " * Starting pv... * "
filename_pv="$(basename "${filename_in}-pv.mkv")" filename_pv="$(basename "${filename_in}-pv.mkv")"
if [[ -e "$filename_pv" ]]; then if [[ -e "$filename_pv" ]]; then
mv -v "$filename_pv" ~/TRASH mv -v "$filename_pv" ~/TRASH
fi fi
pv "$filename_in" "$filename_pv" pv "$filename_in" "$filename_pv"
echo -e "Testing with 'pv' complete!\n" echo -e " * Testing with 'pv' complete! * \n"
fi fi
if [[ "$pv2" == "y" ]]; then if [[ "$pv2" == "y" ]]; then
echo "Starting pv2..." echo " * Starting pv2... * "
filename_pv2="$(basename "${filename_in}-pv2.mkv")" filename_pv2="$(basename "${filename_in}-pv2.mkv")"
if [[ -e "$filename_pv2" ]]; then if [[ -e "$filename_pv2" ]]; then
mv -v "$filename_pv2" ~/TRASH mv -v "$filename_pv2" ~/TRASH
fi fi
pv "$filename_in" "$filename_pv2" pv "$filename_in" "$filename_pv2"
echo -e "Testing with 'pv2' complete!\n" echo -e " * Testing with 'pv2' complete! * \n"
fi fi
echo -e "\nStarting the loop...\n" count=0
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 achannel in $achannels; do for afreq in $afreqs; do
for ext in $exts; do
(( count++ ))
done
done done
done done
done done
done done
plural=""
if (( $count != 1 )); then
plural="s"
fi
echo -e "Expecting ${count} loop${plural}, please be patient.\n"
count=0 count=0
unset vcodec vpreset crf vbr acodec abr ext unset vcodec vpreset crf vbr acodec abr ext
@@ -940,14 +949,14 @@ function pv-test {
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 *) preset="$vpreset" ;;
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 *) preset="$vpreset" ;;
esac esac
fi fi
if [[ -n "$preset" ]]; then if [[ -n "$preset" ]]; then
@@ -979,16 +988,30 @@ function pv-test {
frequency="" frequency=""
if [[ "$afreq" != "default" ]]; then if [[ "$afreq" != "default" ]]; then
if [[ "$acodec" == "libopus" ]]; then
case $afreq in
48000) ;; 24000) ;; 16000) ;; 12000) ;; 8000) ;;
*) echo -e "ERROR: libopus cannot do this, skipping frequency ${afreq}."
continue
;;
esac
fi
frequency="-ar $afreq" frequency="-ar $afreq"
fi fi
newfile="_${size_in}p_${vcodec}-${vpreset}-${crf}-${vbr}_${acodec}-${abr}-${achannel}-${afreq}.${ext}" newfile="_${size_in}p_${vcodec}-${vpreset}-${crf}-${vbr}_${acodec}-${abr}-${achannel}-${afreq}.${ext}"
echo -e " * Parameters for this test: $newfile * \n"
if [[ -e "$newfile" ]]; then if [[ -e "$newfile" ]]; then
mv -v "$newfile" ~/TRASH/ echo "Unfinished version of this file already exists, removing."
rm -v "$newfile" ~/TRASH/
fi
if [[ -e *"$newfile" ]]; then
echo "Completed version of this file already exists, skipping."
continue
fi fi
echo -e "\n* Starting new run...\n" echo "Starting run..."
echo -e "Parameters for this run: $newfile\n"
start=$SECONDS start=$SECONDS
set -x set -x
@@ -1005,6 +1028,7 @@ function pv-test {
$normalize \ $normalize \
-movflags +faststart \ -movflags +faststart \
"$newfile" "$newfile"
status="$?"
set +x set +x
finish=$SECONDS finish=$SECONDS
@@ -1013,10 +1037,14 @@ function pv-test {
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" "$(basename "${filename_in}_${padded_mins}m${padded_secs}s${newfile}")" if [[ "$status" == 0 ]]; then
mv -v "$newfile" "$(basename "${filename_in}_${padded_mins}m${padded_secs}s${newfile}")"
else
echo "ERROR: ffmpeg exited with status $status, not renaming file."
fi
echo -e "\n* Finished in ${minutes}m${seconds}s!\n" echo -e "\n * Finished in ${minutes}m${seconds}s! * \n"
count=$(( count++ )) (( count++ ))
done done
done done done done
done done done done