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 # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # 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 function clean_line () # $1: Fill size
{ {
printf "\r% $1s\r" "" printf "\r%$1s\r" ""
} }
function framerate () function framerate ()
@ -28,10 +30,7 @@ function framerate ()
do do
if [[ $(jq -r ".streams[$Index].codec_type" "$StreamsJson") == "video" ]]; then if [[ $(jq -r ".streams[$Index].codec_type" "$StreamsJson") == "video" ]]; then
jq -r ".streams[$Index].r_frame_rate" "$StreamsJson" jq -r ".streams[$Index].r_frame_rate" "$StreamsJson"
return 0 break
fi fi
done done
echo "ERR: No framerate info in $StreamsJson"
exit "$NO_INFO_ERROR"
} }

View File

@ -17,23 +17,19 @@
function extension_by_codec () # $1: Codec function extension_by_codec () # $1: Codec
{ {
# Where is my json?! local Ext=""
local Result=$( for Mux in muxer demuxer
ffprobe -v quiet -h muxer="$1" | \ do
grep 'Common extensions:' | \ # Where is my json?!
sed -r 's|^.+: ([^,\.]+).+|\1|') Ext=$(
if [[ -z "$Result" ]]; then ffprobe -v quiet -h $Mux="$1" | \
Result=$( grep 'Common extensions:' | \
ffprobe -v quiet -h demuxer="$1" | \ sed -r 's|^.+: ([^,\.]+).+|\1|')
grep 'Common extensions:' | \ if [[ -n "$Ext" ]]; then
sed -r 's|^.+: ([^,\.]+).+|\1|') echo "$Ext"
fi break
if [[ -n "$Result" ]]; then fi
echo "$Result" done
else
echo "No extension for codec \"$1\""
exit "$NO_EXTENSION_FOR_CODEC"
fi
} }
function extract_attachments () function extract_attachments ()
@ -86,6 +82,11 @@ do
Codec=$(jq -r ".streams[$Index].codec_name" "$StreamsJson") Codec=$(jq -r ".streams[$Index].codec_name" "$StreamsJson")
Extension=$(extension_by_codec "$Codec") Extension=$(extension_by_codec "$Codec")
if [[ -z "$Extension" ]]; then
echo "No extension for codec \"$Codec\""
exit "$NO_EXTENSION_FOR_CODEC"
fi
case "$Type" in case "$Type" in
video ) video )
ffmpeg -hide_banner -i "$InputFile" -map "0:$Index" -c:v copy "$VideoDir/$Index.$Extension" ffmpeg -hide_banner -i "$InputFile" -map "0:$Index" -c:v copy "$VideoDir/$Index.$Extension"

View File

@ -1,2 +1,32 @@
#!/bin/bash #!/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/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
readonly TmpFramesDir="${FramesDir}_tmp" readonly TmpFramesDir="${FramesDir}_tmp"
readonly ColumnWidth=8
readonly RowTemplate="\r%-${ColumnWidth}s%-${ColumnWidth}s%-${ColumnWidth}s%-${ColumnWidth}s\n"
function create_default_conf () function create_default_conf ()
{ {
echo "\ echo "\
ScaleRatio=\"3\" Process=\"cudnn\"\
OutputDepth=\"16\" GpuNum=\"0\"\
Mode=\"noise_scale\" ScaleRatio=\"3\"\
CropSize=\"256\" OutputDepth=\"16\"\
Model=\"upresnet10\" Mode=\"noise_scale\"\
CropSize=\"256\"\
BatchSize=\"1\"\
Model=\"upresnet10\"\
TtaMode=\"0\"\
" > "$Waifu2xConf" " > "$Waifu2xConf"
} }
@ -135,7 +141,7 @@ function progress_bar ()
LastUpscaledFrame=$(ls "$FramesUpscaledDir" | sort | tail -n 1) LastUpscaledFrame=$(ls "$FramesUpscaledDir" | sort | tail -n 1)
if [[ "$PreviousUpscaledFrame" != "$LastUpscaledFrame" ]]; then if [[ "$PreviousUpscaledFrame" != "$LastUpscaledFrame" ]]; then
local Done=$(to_int $LastUpscaledFrame) 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" PreviousUpscaledFrame="$LastUpscaledFrame"
fi fi
sleep 1 sleep 1
@ -169,23 +175,29 @@ if [[ "$LastUpscaledFrame" == "$LastOriginalFrame" ]]; then
fi fi
LastUpscaledFrame=$(to_int "$LastUpscaledFrame") LastUpscaledFrame=$(to_int "$LastUpscaledFrame")
echo "$WIDTH"
printf "${BLD}$RowTemplate${DEF}" "START" "END" "NOISE" "ACTION"
while read Line while read Line
do do
if [[ -z "$Line" ]]; then
continue
fi
set_range $Line set_range $Line
clean_line 32 clean_line "$COLUMNS"
if [[ -n "$LastUpscaledFrame" ]] && [[ "$LastUpscaledFrame" -ge "$EndFrame" ]]; then if [[ -n "$LastUpscaledFrame" ]] && [[ "$LastUpscaledFrame" -ge "$EndFrame" ]]; then
echo -e "\r$StartFrame - $EndFrame [$NoiseLevel] - SKIP" printf "$RowTemplate" "$StartFrame" "$EndFrame" "$NoiseLevel" "SKIP"
continue continue
fi fi
if [[ -n "$LastUpscaledFrame" ]] && [[ "$StartFrame" -lt "$LastUpscaledFrame" ]]; then 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 # 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 # so it's better to start by overwriting the last upscaled file
StartFrame="$LastUpscaledFrame" StartFrame="$LastUpscaledFrame"
else else
echo -e "\r$StartFrame - $EndFrame [$NoiseLevel]" printf "$RowTemplate" "$StartFrame" "$EndFrame" "$NoiseLevel"
fi fi
rm -rf "$TmpFramesDir" rm -rf "$TmpFramesDir"
@ -202,7 +214,7 @@ do
cp $CopyList "$TmpFramesDir" cp $CopyList "$TmpFramesDir"
popd > /dev/null popd > /dev/null
clean_line 32 clean_line "$COLUMNS"
(progress_bar) & (progress_bar) &
ProgressBarPID=$! ProgressBarPID=$!

View File

@ -54,10 +54,7 @@ source "$FfmpegConf"
rm -rf "$VideoUpscaledDir"; mkdir -p "$VideoUpscaledDir" rm -rf "$VideoUpscaledDir"; mkdir -p "$VideoUpscaledDir"
# videoname? VideoUpscaled="$VideoUpscaledDir/video.mp4"
#VideoName=$(find "$VideoDir" -type f -printf "%f\n" | head -n 1)
VideoName="0.h265"
VideoUpscaled="$VideoUpscaledDir/$VideoName"
ffmpeg \ ffmpeg \
-hide_banner \ -hide_banner \