diff --git a/scripts/common.lib b/scripts/common.lib
index e4ad75a..fc68585 100644
--- a/scripts/common.lib
+++ b/scripts/common.lib
@@ -15,9 +15,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
+DEF='\e[0m'; BLD='\e[1m'; RED='\e[31m'; GRN='\e[32m'; YLW='\e[33m'; WHT='\e[97m'
+
function clean_line () # $1: Fill size
{
- printf "\r% $1s\r" ""
+ printf "\r%$1s\r" ""
}
function framerate ()
@@ -28,10 +30,7 @@ function framerate ()
do
if [[ $(jq -r ".streams[$Index].codec_type" "$StreamsJson") == "video" ]]; then
jq -r ".streams[$Index].r_frame_rate" "$StreamsJson"
- return 0
+ break
fi
done
-
- echo "ERR: No framerate info in $StreamsJson"
- exit "$NO_INFO_ERROR"
}
diff --git a/scripts/extract.sh b/scripts/extract.sh
index 7478222..f221537 100644
--- a/scripts/extract.sh
+++ b/scripts/extract.sh
@@ -17,23 +17,19 @@
function extension_by_codec () # $1: Codec
{
- # Where is my json?!
- local Result=$(
- ffprobe -v quiet -h muxer="$1" | \
- grep 'Common extensions:' | \
- sed -r 's|^.+: ([^,\.]+).+|\1|')
- if [[ -z "$Result" ]]; then
- Result=$(
- ffprobe -v quiet -h demuxer="$1" | \
- grep 'Common extensions:' | \
- sed -r 's|^.+: ([^,\.]+).+|\1|')
- fi
- if [[ -n "$Result" ]]; then
- echo "$Result"
- else
- echo "No extension for codec \"$1\""
- exit "$NO_EXTENSION_FOR_CODEC"
- fi
+ local Ext=""
+ for Mux in muxer demuxer
+ do
+ # Where is my json?!
+ Ext=$(
+ ffprobe -v quiet -h $Mux="$1" | \
+ grep 'Common extensions:' | \
+ sed -r 's|^.+: ([^,\.]+).+|\1|')
+ if [[ -n "$Ext" ]]; then
+ echo "$Ext"
+ break
+ fi
+ done
}
function extract_attachments ()
@@ -86,6 +82,11 @@ do
Codec=$(jq -r ".streams[$Index].codec_name" "$StreamsJson")
Extension=$(extension_by_codec "$Codec")
+ if [[ -z "$Extension" ]]; then
+ echo "No extension for codec \"$Codec\""
+ exit "$NO_EXTENSION_FOR_CODEC"
+ fi
+
case "$Type" in
video )
ffmpeg -hide_banner -i "$InputFile" -map "0:$Index" -c:v copy "$VideoDir/$Index.$Extension"
diff --git a/scripts/test.sh b/scripts/test.sh
index 05a7907..ff3a728 100644
--- a/scripts/test.sh
+++ b/scripts/test.sh
@@ -1,2 +1,32 @@
#!/bin/bash
+Symbols=16
+
+function HammingDistance () # $1: Prev, $2: Current
+{
+ local Dist=0
+ local PrevPart
+ local CurrentPart
+ for (( i=1; i<=$Symbols; i++ ))
+ do
+ PrevPart=$((16#$(echo "$1" | cut -c "$i")))
+ CurrentPart=$((16#$(echo "$2" | cut -c "$i")))
+ Offset=$(echo $((PrevPart-CurrentPart)) | sed 's|-||')
+ ((Dist+=Offset))
+ done
+ echo "$Dist"
+}
+
+HashList="./hash.list"
+PrevHash=$(printf "%0${Symbols}s" "")
+:> "$HashList"
+
+find "$FramesDir" -type f -printf "%f\n" | \
+while read Image
+do
+ Hash=$(./dependencies/go-perceptualhash/go-perceptualhash.exe --bits 8 --digest -f "$FramesDir/$Image")
+ Distance=$(HammingDistance "$PrevHash" "$Hash")
+ PrevHash="$Hash"
+ echo -e "$Image\t$Hash\t$Distance"
+ echo -e "$Image\t$Hash\t$Distance" >> "$HashList"
+done
diff --git a/scripts/upscale.sh b/scripts/upscale.sh
index 02189ae..39396b7 100644
--- a/scripts/upscale.sh
+++ b/scripts/upscale.sh
@@ -16,15 +16,21 @@
# along with this program. If not, see .
readonly TmpFramesDir="${FramesDir}_tmp"
+readonly ColumnWidth=8
+readonly RowTemplate="\r%-${ColumnWidth}s%-${ColumnWidth}s%-${ColumnWidth}s%-${ColumnWidth}s\n"
function create_default_conf ()
{
echo "\
-ScaleRatio=\"3\"
-OutputDepth=\"16\"
-Mode=\"noise_scale\"
-CropSize=\"256\"
-Model=\"upresnet10\"
+Process=\"cudnn\"\
+GpuNum=\"0\"\
+ScaleRatio=\"3\"\
+OutputDepth=\"16\"\
+Mode=\"noise_scale\"\
+CropSize=\"256\"\
+BatchSize=\"1\"\
+Model=\"upresnet10\"\
+TtaMode=\"0\"\
" > "$Waifu2xConf"
}
@@ -135,7 +141,7 @@ function progress_bar ()
LastUpscaledFrame=$(ls "$FramesUpscaledDir" | sort | tail -n 1)
if [[ "$PreviousUpscaledFrame" != "$LastUpscaledFrame" ]]; then
local Done=$(to_int $LastUpscaledFrame)
- echo -ne "\r[$(printf "% 3d" $(($Done*100/$Total)))%] $Done/$Total"
+ printf "\r[%3d%%] %d/%d" "$(($Done*100/$Total))" "$Done" "$Total"
PreviousUpscaledFrame="$LastUpscaledFrame"
fi
sleep 1
@@ -169,23 +175,29 @@ if [[ "$LastUpscaledFrame" == "$LastOriginalFrame" ]]; then
fi
LastUpscaledFrame=$(to_int "$LastUpscaledFrame")
-
+echo "$WIDTH"
+printf "${BLD}$RowTemplate${DEF}" "START" "END" "NOISE" "ACTION"
while read Line
do
+ if [[ -z "$Line" ]]; then
+ continue
+ fi
+
set_range $Line
- clean_line 32
+ clean_line "$COLUMNS"
if [[ -n "$LastUpscaledFrame" ]] && [[ "$LastUpscaledFrame" -ge "$EndFrame" ]]; then
- echo -e "\r$StartFrame - $EndFrame [$NoiseLevel] - SKIP"
+ printf "$RowTemplate" "$StartFrame" "$EndFrame" "$NoiseLevel" "SKIP"
continue
fi
if [[ -n "$LastUpscaledFrame" ]] && [[ "$StartFrame" -lt "$LastUpscaledFrame" ]]; then
- echo -e "\r$StartFrame ($LastUpscaledFrame) - $EndFrame [$NoiseLevel] - CONTINUE"
+ printf "$RowTemplate" "$StartFrame" "$(($LastUpscaledFrame-1))" "$NoiseLevel" "SKIP"
+ printf "$RowTemplate" "$LastUpscaledFrame" "$EndFrame" "$NoiseLevel" "CONTINUE"
# if waifu2x-caffe was interrupted while saving the file, a corrupted file is saved
# so it's better to start by overwriting the last upscaled file
StartFrame="$LastUpscaledFrame"
else
- echo -e "\r$StartFrame - $EndFrame [$NoiseLevel]"
+ printf "$RowTemplate" "$StartFrame" "$EndFrame" "$NoiseLevel"
fi
rm -rf "$TmpFramesDir"
@@ -202,7 +214,7 @@ do
cp $CopyList "$TmpFramesDir"
popd > /dev/null
- clean_line 32
+ clean_line "$COLUMNS"
(progress_bar) &
ProgressBarPID=$!
diff --git a/scripts/video.sh b/scripts/video.sh
index 5f15e32..637d308 100644
--- a/scripts/video.sh
+++ b/scripts/video.sh
@@ -54,10 +54,7 @@ source "$FfmpegConf"
rm -rf "$VideoUpscaledDir"; mkdir -p "$VideoUpscaledDir"
-# videoname?
-#VideoName=$(find "$VideoDir" -type f -printf "%f\n" | head -n 1)
-VideoName="0.h265"
-VideoUpscaled="$VideoUpscaledDir/$VideoName"
+VideoUpscaled="$VideoUpscaledDir/video.mp4"
ffmpeg \
-hide_banner \