-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path2x.sh
executable file
·50 lines (41 loc) · 1.41 KB
/
2x.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# Needs to be exactly 2 arguments, and they must be directories
if [ ! $# -eq 2 ] || [ ! -d "$1" ] || [ ! -d "$2" ]; then
echo "Usage: ${0##*/} input_dir output_dir"
exit
fi
# You can set these permanently and remove the above section
input_dir=${1%/}
output_dir=${2%/}
# Check if there's any files to process
filesfound=$(find "$input_dir" -type f)
if [ -z "$filesfound" ]; then
echo 'No files to process, exiting!'
exit
fi
while IFS= read -r fullfilepath; do
# Path but without $input_dir
shortfilepath="${fullfilepath#*$input_dir}"
# Create directory (remove everything after /)
mkdir -p "$output_dir/${shortfilepath%/*}"
# Print current file being upscaled, without leading /
echo -n "Upscaling ${shortfilepath#*/} "
# Verbose, TTA, webp format
fulloutput=$(
waifu2x-ncnn-vulkan -v -x -f webp \
-i "${input_dir}${shortfilepath}" \
-o "${output_dir}${shortfilepath%.*}".webp 2>&1
)
if echo "$fulloutput" | grep -q "done"; then
echo "done!"
rm "${input_dir}${shortfilepath}"
else
echo -n 'failed: '
# Print error in red and move on
ERROR=$(echo "$fulloutput" | grep -v -e '^\[' -e 'Experimental compiler')
echo -e "\033[0;31m$ERROR\033[0m"
continue
fi
done <<<"$filesfound"
# Remove any empty directories left behind
find "$input_dir" -mindepth 1 -type d -empty -delete