From a557e636eaeaea80cda6092a0852c15a5e721e59 Mon Sep 17 00:00:00 2001 From: GenZmeY Date: Mon, 28 Dec 2020 15:44:01 +0300 Subject: [PATCH] add settings for preview --- scripts/common.lib | 1 + scripts/preview.sh | 30 ++++++++++++++++++++++-------- scripts/ranges.sh | 6 +++++- settings/preview.conf | 7 +++++++ 4 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 settings/preview.conf diff --git a/scripts/common.lib b/scripts/common.lib index 4ca8beb..b7e06e9 100644 --- a/scripts/common.lib +++ b/scripts/common.lib @@ -41,6 +41,7 @@ readonly RangesList="$OutputDir/ranges.list" readonly DepsConf="$SettingsDir/deps.conf" readonly Waifu2xConf="$SettingsDir/waifu2x-caffe.conf" +readonly PreviewConf="$SettingsDir/preview.conf" readonly FfmpegConf="$SettingsDir/ffmpeg.conf" readonly RangeGenConf="$SettingsDir/range-gen.conf" diff --git a/scripts/preview.sh b/scripts/preview.sh index 9e23799..e6ef17f 100644 --- a/scripts/preview.sh +++ b/scripts/preview.sh @@ -16,6 +16,7 @@ # along with this program. If not, see . source "$Waifu2xConf" +source "$PreviewConf" readonly TmpFramesSrcDir="${PreviewDir}_tmpsrc" readonly TmpFramesOutDir="${PreviewDir}_tmpout" @@ -45,15 +46,26 @@ do EndFrame=$(png_num ${RangeInfo[1]}) TargetFrame=$((StartFrame + (EndFrame - StartFrame)/2)) - CopyList+="$(printf "%06d" $TargetFrame).png " + CopyList+="$(printf "%06d" $TargetFrame).png " # faster than copying one by one done < <(cat "$RangesList"; echo) # make bash not skip the last line (if there is no empty line at the end) pushd "$FramesDir" > /dev/null cp -f $CopyList "$TmpFramesSrcDir" popd > /dev/null +if echo "$UseRangeNumbers" | grep -qiF "True"; then + pushd "$TmpFramesSrcDir" > /dev/null + Index=0 + while read File + do + ((Index+=1)) + mv "$File" "$(printf "%06d" $Index).png" + done < <(find "$TmpFramesSrcDir" -type f -name '*.png' -printf '%f\n') + popd > /dev/null +fi + # Upscale (scale) -if [[ "$ScaleRatio" -ne 1 ]]; then +if echo "$Waifu2xScalePreview" | grep -qiF "True" && [[ "$ScaleRatio" -ne 1 ]]; then echo "waifu2x scale" waifu2x-caffe-cui \ --mode "scale" \ @@ -79,7 +91,7 @@ if [[ "$ScaleRatio" -ne 1 ]]; then fi # Upscale (noise_scale) -for NoiseLevel in 0 1 2 3 +for NoiseLevel in $Waifu2xNoiseScaleList do if [[ "$ScaleRatio" -eq 1 ]]; then UpscaleMode="noise" @@ -112,10 +124,12 @@ do popd > /dev/null done -echo "scale original" -mogrify -scale $(echo "$ScaleRatio * 100" | bc)% "$TmpFramesSrcDir"/*.png -pushd "$TmpFramesSrcDir" > /dev/null -mv *.png "$PreviewDir" -popd > /dev/null +if echo "$ResizePreivew" | grep -qiF "True"; then + echo "scale original" + mogrify -scale $(echo "$ScaleRatio * 100" | bc)% "$TmpFramesSrcDir"/*.png + pushd "$TmpFramesSrcDir" > /dev/null + mv *.png "$PreviewDir" + popd > /dev/null +fi rm -rf "$TmpFramesSrcDir" "$TmpFramesOutDir" \ No newline at end of file diff --git a/scripts/ranges.sh b/scripts/ranges.sh index 17860ac..1338cef 100644 --- a/scripts/ranges.sh +++ b/scripts/ranges.sh @@ -22,4 +22,8 @@ source "$RangeGenConf" -"$DepsDir/range-gen/range-gen.exe" -j "$Jobs" -n "$NoiseLevel" "$FramesDir" "$RangesList" "$Threshold" +if [[ -n "$NoiseLevel" ]]; then + "$DepsDir/range-gen/range-gen.exe" -j "$Jobs" -n "$NoiseLevel" "$FramesDir" "$RangesList" "$Threshold" +else + "$DepsDir/range-gen/range-gen.exe" -j "$Jobs" "$FramesDir" "$RangesList" "$Threshold" +fi diff --git a/settings/preview.conf b/settings/preview.conf new file mode 100644 index 0000000..af8097d --- /dev/null +++ b/settings/preview.conf @@ -0,0 +1,7 @@ +### Preview gen settings ### + +UseRangeNumbers="True" # (Instead of frame numbers) + +ResizePreivew="False" # Resize original frames with ImageMagisk +Waifu2xScalePreview="False" # Generate preview for Waifu2x scale mode +Waifu2xNoiseScaleList="0 1 3" # Preview for Waifu2x noise_scale mode. Specify noise reduction levels in the list.