This commit is contained in:
GenZmeY 2020-10-28 03:09:35 +03:00
parent df579e6082
commit ab46134e7b
5 changed files with 77 additions and 38 deletions

View File

@ -15,9 +15,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
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"
}

View File

@ -17,23 +17,19 @@
function extension_by_codec () # $1: Codec
{
local Ext=""
for Mux in muxer demuxer
do
# 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" | \
Ext=$(
ffprobe -v quiet -h $Mux="$1" | \
grep 'Common extensions:' | \
sed -r 's|^.+: ([^,\.]+).+|\1|')
if [[ -n "$Ext" ]]; then
echo "$Ext"
break
fi
if [[ -n "$Result" ]]; then
echo "$Result"
else
echo "No extension for codec \"$1\""
exit "$NO_EXTENSION_FOR_CODEC"
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"

View File

@ -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

View File

@ -16,15 +16,21 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
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=$!

View File

@ -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 \