v0.2
- add preview mode; - deps config; - upscale mode is selected automatically; - add scale mode support (i.e. without noise reduction); - refactoring.
This commit is contained in:
parent
bf8b8bae63
commit
3acbb56f87
@ -15,11 +15,64 @@
|
|||||||
# 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'
|
######## Filesystem ########
|
||||||
|
readonly DepsDir="$BaseDir/dependencies"
|
||||||
|
readonly ScriptsDir="$BaseDir/scripts"
|
||||||
|
readonly SettingsDir="$BaseDir/settings"
|
||||||
|
readonly OutputDir="$BaseDir/output"
|
||||||
|
|
||||||
function clean_line () # $1: Fill size
|
readonly FramesDir="$OutputDir/frames"
|
||||||
|
readonly AudioDir="$OutputDir/audio"
|
||||||
|
readonly VideoDir="$OutputDir/video"
|
||||||
|
readonly SubtitlesDir="$OutputDir/subtitles"
|
||||||
|
readonly ChaptersDir="$OutputDir/chapters"
|
||||||
|
readonly AttachmentsDir="$OutputDir/attachments"
|
||||||
|
readonly ReleaseDir="$OutputDir/release"
|
||||||
|
readonly PreviewDir="$OutputDir/preview"
|
||||||
|
|
||||||
|
readonly FramesUpscaledDir="${FramesDir}_upscaled"
|
||||||
|
readonly VideoUpscaledDir="${VideoDir}_upscaled"
|
||||||
|
|
||||||
|
readonly FormatJson="$OutputDir/format.json"
|
||||||
|
readonly StreamsJson="$OutputDir/streams.json"
|
||||||
|
readonly ChaptersJson="$OutputDir/chapters.json"
|
||||||
|
|
||||||
|
readonly RangesList="$OutputDir/ranges.list"
|
||||||
|
|
||||||
|
readonly DepsConf="$SettingsDir/deps.conf"
|
||||||
|
readonly Waifu2xConf="$SettingsDir/waifu2x-caffe.conf"
|
||||||
|
readonly FfmpegConf="$SettingsDir/ffmpeg.conf"
|
||||||
|
readonly RangeGenConf="$SettingsDir/range-gen.conf"
|
||||||
|
|
||||||
|
######## Return codes ########
|
||||||
|
SUCCESS=0
|
||||||
|
OPTION_ERROR=1
|
||||||
|
PARAMETER_ERROR=2
|
||||||
|
EXTRACT_AUDIO_ERROR=3
|
||||||
|
EXTRACT_VIDEO_ERROR=4
|
||||||
|
EXTRACT_SUBTITLE_ERROR=5
|
||||||
|
EXTRACT_ATTACHMENT_ERROR=6
|
||||||
|
UNKNOWN_CODEC_TYPE_ERROR=7
|
||||||
|
NO_EXTENSION_FOR_CODEC=8
|
||||||
|
CONVERT_TO_FRAMES_ERROR=9
|
||||||
|
FILE_READ_ERROR=10
|
||||||
|
RANGES_LIST_SYNTAX_ERROR=11
|
||||||
|
SETTINGS_ERROR=12
|
||||||
|
WAIFU2X_ERROR=13
|
||||||
|
MERGE_RELEASE_ERROR=14
|
||||||
|
NO_INFO_ERROR=15
|
||||||
|
INTERRUPT=16
|
||||||
|
CREATE_UPSCALED_VIDEO_ERROR=17
|
||||||
|
|
||||||
|
######## Functions ########
|
||||||
|
function clean_line ()
|
||||||
{
|
{
|
||||||
printf "\r%$1s\r" ""
|
printf "\r%$(tput cols)s\r" ""
|
||||||
|
}
|
||||||
|
|
||||||
|
function model_path () # $1: model name
|
||||||
|
{
|
||||||
|
echo "$(dirname $(readlink -e $(which waifu2x-caffe-cui)))/models/$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
function framerate ()
|
function framerate ()
|
||||||
@ -34,3 +87,87 @@ function framerate ()
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function png_num () # $1: String
|
||||||
|
{
|
||||||
|
echo "$1" | \
|
||||||
|
sed 's|.png||' | \
|
||||||
|
sed -r 's|0*([1-9][0-9]*)|\1|'
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_ranges ()
|
||||||
|
{
|
||||||
|
local Errors=0
|
||||||
|
local ParamCount=0
|
||||||
|
local LineIndex=0
|
||||||
|
local LastEndFrame=""
|
||||||
|
|
||||||
|
while read Line
|
||||||
|
do
|
||||||
|
((LineIndex++))
|
||||||
|
local RangeInfo=($Line)
|
||||||
|
local ParamCount=${#RangeInfo[@]}
|
||||||
|
|
||||||
|
if [[ "$ParamCount" -eq 0 ]]; then
|
||||||
|
continue
|
||||||
|
elif [[ "$ParamCount" -eq 2 ]] || [[ "$ParamCount" -eq 3 ]]; then
|
||||||
|
local StartFrame=$(png_num ${RangeInfo[0]})
|
||||||
|
local EndFrame=$(png_num ${RangeInfo[1]})
|
||||||
|
local NoiseLevel=$(png_num ${RangeInfo[2]})
|
||||||
|
|
||||||
|
if [[ "$StartFrame" =~ ^[0-9]+$ ]]; then
|
||||||
|
if [[ -n "$LastEndFrame" ]] && [[ $(($LastEndFrame+1)) != $StartFrame ]]; then
|
||||||
|
echo "ERR [$LineIndex]: StartFrame ($StartFrame) doesn't follow the previous one ($LastEndFrame)"
|
||||||
|
((Errors++))
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "ERR [$LineIndex]: StartFrame $StartFrame is not valid integer"
|
||||||
|
((Errors++))
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$EndFrame" =~ ^[0-9]+$ ]]; then
|
||||||
|
LastEndFrame="$EndFrame"
|
||||||
|
else
|
||||||
|
LastEndFrame=""
|
||||||
|
echo "ERR [$LineIndex]: EndFrame $EndFrame is not valid integer"
|
||||||
|
((Errors++))
|
||||||
|
fi
|
||||||
|
if [[ "$NoiseLevel" =~ ^[0-9]+$ ]]; then
|
||||||
|
if [[ "$NoiseLevel" -lt 0 ]] || [[ "$NoiseLevel" -gt 3 ]]; then
|
||||||
|
echo "ERR [$LineIndex]: NoiseLevel $NoiseLevel incorrect value (should be in the range 0-3)"
|
||||||
|
((Errors++))
|
||||||
|
fi
|
||||||
|
elif [[ -n "$NoiseLevel" ]]; then
|
||||||
|
echo "ERR [$LineIndex]: NoiseLevel $NoiseLevel is not valid integer"
|
||||||
|
((Errors++))
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "ERR [$LineIndex]: $ParamCount parameters received (2 or 3 expected)"
|
||||||
|
((Errors++))
|
||||||
|
fi
|
||||||
|
done < <(cat "$RangesList"; echo) # make bash not skip the last line (if there is no empty line at the end)
|
||||||
|
if [[ "$Errors" -gt 0 ]]; then
|
||||||
|
echo "Ranges list syntax: $Errors errors"
|
||||||
|
fi
|
||||||
|
return "$Errors"
|
||||||
|
}
|
||||||
|
|
||||||
|
######## Includes ########
|
||||||
|
source "$DepsConf"
|
||||||
|
|
||||||
|
######## Initialization ########
|
||||||
|
if [[ -n "$Waifu2xCaffeDir" ]]; then
|
||||||
|
PATH="$PATH:$(readlink -e $Waifu2xCaffeDir)"
|
||||||
|
fi
|
||||||
|
if [[ -n "$MkvToolNixDir" ]]; then
|
||||||
|
PATH="$PATH:$(readlink -e $MkvToolNixDir)"
|
||||||
|
fi
|
||||||
|
if [[ -n "$FfmpegDir" ]]; then
|
||||||
|
PATH="$PATH:$(readlink -e $FfmpegDir)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
|
||||||
|
DEF='\e[0m'; BLD='\e[1m'; RED='\e[31m'; GRN='\e[32m'; YLW='\e[33m'; WHT='\e[97m'
|
||||||
|
else
|
||||||
|
DEF=''; BLD=''; RED=''; GRN=''; YLW=''; WHT=''
|
||||||
|
fi
|
||||||
|
@ -36,12 +36,13 @@ function extract_attachments ()
|
|||||||
{
|
{
|
||||||
pushd "$AttachmentsDir"
|
pushd "$AttachmentsDir"
|
||||||
|
|
||||||
ffmpeg -hide_banner -dump_attachment:t "" -i "$InputFile"
|
# Disable error checking
|
||||||
|
|
||||||
# There is no error checking,
|
|
||||||
# because ffmpeg always throws an error:
|
# because ffmpeg always throws an error:
|
||||||
# "At least one output file must be specified",
|
# "At least one output file must be specified",
|
||||||
# although it successfully saves attachments.
|
# although it successfully saves attachments.
|
||||||
|
set +e
|
||||||
|
ffmpeg -hide_banner -dump_attachment:t "" -i "$InputFile"
|
||||||
|
set -e
|
||||||
|
|
||||||
popd
|
popd
|
||||||
}
|
}
|
||||||
|
@ -17,15 +17,6 @@
|
|||||||
|
|
||||||
InputFile=$(find "$VideoDir" -mindepth 1 -maxdepth 1 -type f | head -n 1)
|
InputFile=$(find "$VideoDir" -mindepth 1 -maxdepth 1 -type f | head -n 1)
|
||||||
|
|
||||||
if ! [[ -r "$InputFile" ]]; then
|
|
||||||
echo "Read file error: \"$InputFile\""
|
|
||||||
exit "$FILE_READ_ERROR"
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -rf "$FramesDir"; mkdir -p "$FramesDir"
|
rm -rf "$FramesDir"; mkdir -p "$FramesDir"
|
||||||
|
|
||||||
ffmpeg -hide_banner -i "$InputFile" -r "$(framerate)" -f image2 "$FramesDir/%06d.png"
|
ffmpeg -hide_banner -i "$InputFile" -r "$(framerate)" -f image2 "$FramesDir/%06d.png"
|
||||||
|
|
||||||
if [[ "$?" != 0 ]]; then
|
|
||||||
exit "$CONVERT_TO_FRAMES_ERROR"
|
|
||||||
fi
|
|
||||||
|
121
scripts/preview.sh
Normal file
121
scripts/preview.sh
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This file is part of video2d-2x.
|
||||||
|
#
|
||||||
|
# video2d-2x is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
source "$Waifu2xConf"
|
||||||
|
|
||||||
|
readonly TmpFramesSrcDir="${PreviewDir}_tmpsrc"
|
||||||
|
readonly TmpFramesOutDir="${PreviewDir}_tmpout"
|
||||||
|
|
||||||
|
if ! [[ -r "$RangesList" ]]; then
|
||||||
|
echo "Read file error: \"$RangesList\""
|
||||||
|
exit "$FILE_READ_ERROR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! check_ranges; then
|
||||||
|
exit "$RANGES_LIST_SYNTAX_ERROR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf "$PreviewDir" "$TmpFramesSrcDir" "$TmpFramesOutDir"
|
||||||
|
mkdir -p "$PreviewDir" "$TmpFramesSrcDir" "$TmpFramesOutDir"
|
||||||
|
|
||||||
|
# Prepare frames
|
||||||
|
CopyList=""
|
||||||
|
while read Line
|
||||||
|
do
|
||||||
|
if [[ -z "$Line" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
RangeInfo=($Line)
|
||||||
|
StartFrame=$(png_num ${RangeInfo[0]})
|
||||||
|
EndFrame=$(png_num ${RangeInfo[1]})
|
||||||
|
TargetFrame=$((StartFrame + (EndFrame - StartFrame)/2))
|
||||||
|
|
||||||
|
CopyList+="$(printf "%06d" $TargetFrame).png "
|
||||||
|
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
|
||||||
|
|
||||||
|
# Upscale (scale)
|
||||||
|
if [[ "$ScaleRatio" -ne 1 ]]; then
|
||||||
|
echo "Scale"
|
||||||
|
waifu2x-caffe-cui \
|
||||||
|
--mode "scale" \
|
||||||
|
--scale_ratio "$ScaleRatio" \
|
||||||
|
--output_depth "$OutputDepth" \
|
||||||
|
--tta "$TtaMode" \
|
||||||
|
--gpu "$GpuNum" \
|
||||||
|
--process "$Process" \
|
||||||
|
--crop_size "$CropSize" \
|
||||||
|
--batch_size "$BatchSize" \
|
||||||
|
--model_dir "$(model_path $Model)" \
|
||||||
|
--input_path "$TmpFramesSrcDir" \
|
||||||
|
--output_path "$TmpFramesOutDir" \
|
||||||
|
> /dev/null
|
||||||
|
|
||||||
|
echo "Copy"
|
||||||
|
pushd "$TmpFramesOutDir" > /dev/null
|
||||||
|
while read Filename
|
||||||
|
do
|
||||||
|
NewFilename=$(echo "$Filename" | sed "s|.png|_scale${ScaleRatio}.png|")
|
||||||
|
mv "$Filename" "$PreviewDir/$NewFilename"
|
||||||
|
done < <(find "$TmpFramesOutDir" -type f -name '*.png' -printf "%f\n")
|
||||||
|
popd > /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Upscale (noise_scale)
|
||||||
|
for NoiseLevel in 0 1 2 3
|
||||||
|
do
|
||||||
|
if [[ "$ScaleRatio" -eq 1 ]]; then
|
||||||
|
UpscaleMode="noise"
|
||||||
|
else
|
||||||
|
UpscaleMode="noise_scale"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$UpscaleMode $NoiseLevel"
|
||||||
|
waifu2x-caffe-cui \
|
||||||
|
--mode "$UpscaleMode" \
|
||||||
|
--scale_ratio "$ScaleRatio" \
|
||||||
|
--output_depth "$OutputDepth" \
|
||||||
|
--noise_level "$NoiseLevel" \
|
||||||
|
--tta "$TtaMode" \
|
||||||
|
--gpu "$GpuNum" \
|
||||||
|
--process "$Process" \
|
||||||
|
--crop_size "$CropSize" \
|
||||||
|
--batch_size "$BatchSize" \
|
||||||
|
--model_dir "$(model_path $Model)" \
|
||||||
|
--input_path "$TmpFramesSrcDir" \
|
||||||
|
--output_path "$TmpFramesOutDir" \
|
||||||
|
> /dev/null
|
||||||
|
|
||||||
|
echo "Copy"
|
||||||
|
pushd "$TmpFramesOutDir" > /dev/null
|
||||||
|
while read Filename
|
||||||
|
do
|
||||||
|
NewFilename=$(echo "$Filename" | sed "s|.png|_scale${ScaleRatio}_noise${NoiseLevel}.png|")
|
||||||
|
mv "$Filename" "$PreviewDir/$NewFilename"
|
||||||
|
done < <(find "$TmpFramesOutDir" -type f -name '*.png' -printf "%f\n")
|
||||||
|
popd > /dev/null
|
||||||
|
done
|
||||||
|
|
||||||
|
pushd "$TmpFramesSrcDir" > /dev/null
|
||||||
|
mv *.png "$PreviewDir"
|
||||||
|
popd > /dev/null
|
||||||
|
|
||||||
|
rm -rf "$TmpFramesSrcDir" "$TmpFramesOutDir"
|
@ -15,18 +15,10 @@
|
|||||||
# 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/>.
|
||||||
|
|
||||||
# TODO: auto-detect ranges
|
|
||||||
# compare adjacent frames using the duplicate image search algorithm
|
|
||||||
# frames that are unlike each other will be the boundaries of the ranges
|
|
||||||
|
|
||||||
# Range list format:
|
# Range list format:
|
||||||
# START_FRAME END_FRAME NOISE_LEVEL
|
# START_FRAME END_FRAME NOISE_LEVEL
|
||||||
# (separate line for each range)
|
# (separate line for each range)
|
||||||
|
# (NOISE_LEVEL is optional)
|
||||||
function add_range () # $1: Start frame, $2: End frame, $3: Noise level
|
|
||||||
{
|
|
||||||
echo -e "$1\t$2\t$3" >> "$RangesList"
|
|
||||||
}
|
|
||||||
|
|
||||||
source "$RangeGenConf"
|
source "$RangeGenConf"
|
||||||
|
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
SUCCESS=0
|
|
||||||
OPTION_ERROR=1
|
|
||||||
PARAMETER_ERROR=2
|
|
||||||
EXTRACT_AUDIO_ERROR=3
|
|
||||||
EXTRACT_VIDEO_ERROR=4
|
|
||||||
EXTRACT_SUBTITLE_ERROR=5
|
|
||||||
EXTRACT_ATTACHMENT_ERROR=6
|
|
||||||
UNKNOWN_CODEC_TYPE_ERROR=7
|
|
||||||
NO_EXTENSION_FOR_CODEC=8
|
|
||||||
CONVERT_TO_FRAMES_ERROR=9
|
|
||||||
FILE_READ_ERROR=10
|
|
||||||
RANGES_LIST_SYNTAX_ERROR=11
|
|
||||||
SETTINGS_ERROR=12
|
|
||||||
WAIFU2X_ERROR=13
|
|
||||||
MERGE_RELEASE_ERROR=14
|
|
||||||
NO_INFO_ERROR=15
|
|
||||||
INTERRUPT=16
|
|
||||||
CREATE_UPSCALED_VIDEO_ERROR=17
|
|
@ -15,53 +15,38 @@
|
|||||||
# 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/>.
|
||||||
|
|
||||||
|
source "$Waifu2xConf"
|
||||||
|
|
||||||
readonly TmpFramesDir="${FramesDir}_tmp"
|
readonly TmpFramesDir="${FramesDir}_tmp"
|
||||||
readonly ColumnWidth=8
|
readonly RowTemplate="\r%-8s%-8s%-12s%-8s%-8s\n"
|
||||||
readonly RowTemplate="\r%-${ColumnWidth}s%-${ColumnWidth}s%-${ColumnWidth}s%-${ColumnWidth}s\n"
|
|
||||||
|
|
||||||
function create_default_conf ()
|
function upscale_mode () # $1: ScaleRatio, $2: NoiseLevel
|
||||||
{
|
{
|
||||||
echo "\
|
local ScaleRatio="$1"
|
||||||
Process=\"cudnn\"\
|
local NoiseLevel="$2"
|
||||||
GpuNum=\"0\"\
|
|
||||||
ScaleRatio=\"3\"\
|
|
||||||
OutputDepth=\"16\"\
|
|
||||||
Mode=\"noise_scale\"\
|
|
||||||
CropSize=\"256\"\
|
|
||||||
BatchSize=\"1\"\
|
|
||||||
Model=\"upresnet10\"\
|
|
||||||
TtaMode=\"0\"\
|
|
||||||
" > "$Waifu2xConf"
|
|
||||||
}
|
|
||||||
|
|
||||||
function to_int () # $1: String
|
if [[ "$ScaleRatio" -ne 1 ]] && [[ -n "$NoiseLevel" ]]; then
|
||||||
{
|
echo "noise_scale"
|
||||||
echo "$1" | \
|
return 0
|
||||||
sed 's|.png||' | \
|
fi
|
||||||
sed -r 's|0*([1-9][0-9]*)|\1|'
|
if [[ "$ScaleRatio" -eq 1 ]] && [[ -n "$NoiseLevel" ]]; then
|
||||||
}
|
echo "noise"
|
||||||
|
return 0
|
||||||
function set_range () # $@: Line
|
fi
|
||||||
{
|
if [[ "$ScaleRatio" -ne 1 ]] && [[ -z "$NoiseLevel" ]]; then
|
||||||
StartFrame=$(to_int "$1")
|
echo "scale"
|
||||||
EndFrame=$(to_int "$2")
|
return 0
|
||||||
NoiseLevel=$(to_int "$3")
|
fi
|
||||||
|
return 1
|
||||||
return $#
|
|
||||||
}
|
|
||||||
|
|
||||||
function model_path () # $1: model name
|
|
||||||
{
|
|
||||||
echo "$(dirname $(readlink -e $(which waifu2x-caffe-cui)))/models/$1"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function upscale_images () # $1: InputDir, $2: OutputDir, $3: ProgressBarPID, $4: ParentPID
|
function upscale_images () # $1: InputDir, $2: OutputDir, $3: ProgressBarPID, $4: ParentPID
|
||||||
{
|
{
|
||||||
waifu2x-caffe-cui \
|
waifu2x-caffe-cui \
|
||||||
|
--mode "$UpscaleMode" \
|
||||||
--scale_ratio "$ScaleRatio" \
|
--scale_ratio "$ScaleRatio" \
|
||||||
--output_depth "$OutputDepth" \
|
--output_depth "$OutputDepth" \
|
||||||
--noise_level "$NoiseLevel" \
|
--noise_level "$NoiseLevel" \
|
||||||
--mode "$Mode" \
|
|
||||||
--tta "$TtaMode" \
|
--tta "$TtaMode" \
|
||||||
--gpu "$GpuNum" \
|
--gpu "$GpuNum" \
|
||||||
--process "$Process" \
|
--process "$Process" \
|
||||||
@ -78,69 +63,16 @@ function upscale_images () # $1: InputDir, $2: OutputDir, $3: ProgressBarPID, $4
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_ranges ()
|
|
||||||
{
|
|
||||||
local Errors=0
|
|
||||||
local ParamCount=0
|
|
||||||
local LineIndex=0
|
|
||||||
local LastEndFrame=""
|
|
||||||
|
|
||||||
while read Line
|
|
||||||
do
|
|
||||||
((LineIndex++))
|
|
||||||
set_range $Line
|
|
||||||
ParamCount=$?
|
|
||||||
if [[ "$ParamCount" -eq 0 ]]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
if [[ "$ParamCount" -eq 3 ]]; then
|
|
||||||
if [[ "$StartFrame" =~ ^[0-9]+$ ]]; then
|
|
||||||
if [[ -n "$LastEndFrame" ]] && [[ $(($LastEndFrame+1)) != $StartFrame ]]; then
|
|
||||||
echo "ERR [$LineIndex]: StartFrame ($StartFrame) doesn't follow the previous one ($LastEndFrame)"
|
|
||||||
((Errors++))
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "ERR [$LineIndex]: StartFrame $StartFrame is not valid integer"
|
|
||||||
((Errors++))
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$EndFrame" =~ ^[0-9]+$ ]]; then
|
|
||||||
LastEndFrame="$EndFrame"
|
|
||||||
else
|
|
||||||
LastEndFrame=""
|
|
||||||
echo "ERR [$LineIndex]: EndFrame $EndFrame is not valid integer"
|
|
||||||
((Errors++))
|
|
||||||
fi
|
|
||||||
if [[ "$NoiseLevel" =~ ^[0-9]+$ ]]; then
|
|
||||||
if [[ "$NoiseLevel" -lt 0 ]] || [[ "$NoiseLevel" -gt 3 ]]; then
|
|
||||||
echo "ERR [$LineIndex]: NoiseLevel $NoiseLevel incorrect value (should be in the range 0-3)"
|
|
||||||
((Errors++))
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "ERR [$LineIndex]: NoiseLevel $NoiseLevel is not valid integer"
|
|
||||||
((Errors++))
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "ERR [$LineIndex]: $ParamCount parameters received (3 expected)"
|
|
||||||
((Errors++))
|
|
||||||
fi
|
|
||||||
done < <(cat "$RangesList"; echo) # make bash not skip the last line (if there is no empty line at the end)
|
|
||||||
if [[ "$Errors" -gt 0 ]]; then
|
|
||||||
echo "Ranges list syntax: $Errors errors"
|
|
||||||
fi
|
|
||||||
return "$Errors"
|
|
||||||
}
|
|
||||||
|
|
||||||
function progress_bar ()
|
function progress_bar ()
|
||||||
{
|
{
|
||||||
local PreviousUpscaledFrame=""
|
local PreviousUpscaledFrame=""
|
||||||
local LastUpscaledFrame=""
|
local LastUpscaledFrame=""
|
||||||
local Total=$(to_int $LastOriginalFrame)
|
local Total=$(png_num $LastOriginalFrame)
|
||||||
while [[ "$LastUpscaledFrame" != "$LastOriginalFrame" ]]
|
while [[ "$LastUpscaledFrame" != "$LastOriginalFrame" ]]
|
||||||
do
|
do
|
||||||
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=$(png_num $LastUpscaledFrame)
|
||||||
printf "\r[%3d%%] %d/%d" "$(($Done*100/$Total))" "$Done" "$Total"
|
printf "\r[%3d%%] %d/%d" "$(($Done*100/$Total))" "$Done" "$Total"
|
||||||
PreviousUpscaledFrame="$LastUpscaledFrame"
|
PreviousUpscaledFrame="$LastUpscaledFrame"
|
||||||
fi
|
fi
|
||||||
@ -148,12 +80,11 @@ function progress_bar ()
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! [[ -e "$Waifu2xConf" ]]; then
|
if ! [[ -r "$RangesList" ]]; then
|
||||||
create_default_conf
|
echo "Read file error: \"$RangesList\""
|
||||||
|
exit "$FILE_READ_ERROR"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
source "$Waifu2xConf"
|
|
||||||
|
|
||||||
if ! check_ranges; then
|
if ! check_ranges; then
|
||||||
exit "$RANGES_LIST_SYNTAX_ERROR"
|
exit "$RANGES_LIST_SYNTAX_ERROR"
|
||||||
fi
|
fi
|
||||||
@ -161,11 +92,6 @@ fi
|
|||||||
rm -rf "$TmpFramesDir"
|
rm -rf "$TmpFramesDir"
|
||||||
mkdir -p "$FramesUpscaledDir"
|
mkdir -p "$FramesUpscaledDir"
|
||||||
|
|
||||||
if ! [[ -r "$RangesList" ]]; then
|
|
||||||
echo "Read file error: \"$RangesList\""
|
|
||||||
exit "$FILE_READ_ERROR"
|
|
||||||
fi
|
|
||||||
|
|
||||||
LastOriginalFrame=$(ls "$FramesDir" | sort | tail -n 1)
|
LastOriginalFrame=$(ls "$FramesDir" | sort | tail -n 1)
|
||||||
LastUpscaledFrame=$(ls "$FramesUpscaledDir" | sort | tail -n 1)
|
LastUpscaledFrame=$(ls "$FramesUpscaledDir" | sort | tail -n 1)
|
||||||
|
|
||||||
@ -174,30 +100,43 @@ if [[ "$LastUpscaledFrame" == "$LastOriginalFrame" ]]; then
|
|||||||
exit "$SUCCESS"
|
exit "$SUCCESS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
LastUpscaledFrame=$(to_int "$LastUpscaledFrame")
|
LastUpscaledFrame=$(png_num "$LastUpscaledFrame")
|
||||||
echo "$WIDTH"
|
|
||||||
printf "${BLD}$RowTemplate${DEF}" "START" "END" "NOISE" "ACTION"
|
printf "${BLD}$RowTemplate${DEF}" "START" "END" "MODE" "NOISE" "ACTION"
|
||||||
while read Line
|
while read Line
|
||||||
do
|
do
|
||||||
if [[ -z "$Line" ]]; then
|
if [[ -z "$Line" ]]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
set_range $Line
|
RangeInfo=($Line)
|
||||||
clean_line "$COLUMNS"
|
StartFrame=$(png_num ${RangeInfo[0]})
|
||||||
|
EndFrame=$(png_num ${RangeInfo[1]})
|
||||||
|
NoiseLevel=$(png_num ${RangeInfo[2]})
|
||||||
|
|
||||||
|
UpscaleMode=$(upscale_mode "$ScaleRatio" "$NoiseLevel")
|
||||||
|
|
||||||
|
if [[ -z "$NoiseLevel" ]]; then
|
||||||
|
NoiseLevel="0"
|
||||||
|
NoiseLevelDisplay="-"
|
||||||
|
else
|
||||||
|
NoiseLevelDisplay="$NoiseLevel"
|
||||||
|
fi
|
||||||
|
|
||||||
|
clean_line
|
||||||
if [[ -n "$LastUpscaledFrame" ]] && [[ "$LastUpscaledFrame" -ge "$EndFrame" ]]; then
|
if [[ -n "$LastUpscaledFrame" ]] && [[ "$LastUpscaledFrame" -ge "$EndFrame" ]]; then
|
||||||
printf "$RowTemplate" "$StartFrame" "$EndFrame" "$NoiseLevel" "SKIP"
|
printf "$RowTemplate" "$StartFrame" "$EndFrame" "$UpscaleMode" "$NoiseLevelDisplay" "SKIP"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "$LastUpscaledFrame" ]] && [[ "$StartFrame" -lt "$LastUpscaledFrame" ]]; then
|
if [[ -n "$LastUpscaledFrame" ]] && [[ "$StartFrame" -lt "$LastUpscaledFrame" ]]; then
|
||||||
printf "$RowTemplate" "$StartFrame" "$(($LastUpscaledFrame-1))" "$NoiseLevel" "SKIP"
|
printf "$RowTemplate" "$StartFrame" "$(($LastUpscaledFrame-1))" "$UpscaleMode" "$NoiseLevelDisplay" "SKIP"
|
||||||
printf "$RowTemplate" "$LastUpscaledFrame" "$EndFrame" "$NoiseLevel" "CONTINUE"
|
printf "$RowTemplate" "$LastUpscaledFrame" "$EndFrame" "$UpscaleMode" "$NoiseLevelDisplay" "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
|
||||||
printf "$RowTemplate" "$StartFrame" "$EndFrame" "$NoiseLevel"
|
printf "$RowTemplate" "$StartFrame" "$EndFrame" "$UpscaleMode" "$NoiseLevelDisplay"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -rf "$TmpFramesDir"
|
rm -rf "$TmpFramesDir"
|
||||||
@ -214,7 +153,7 @@ do
|
|||||||
cp $CopyList "$TmpFramesDir"
|
cp $CopyList "$TmpFramesDir"
|
||||||
popd > /dev/null
|
popd > /dev/null
|
||||||
|
|
||||||
clean_line "$COLUMNS"
|
clean_line
|
||||||
|
|
||||||
(progress_bar) &
|
(progress_bar) &
|
||||||
ProgressBarPID=$!
|
ProgressBarPID=$!
|
||||||
|
@ -41,7 +41,6 @@ function auto_bitrate ()
|
|||||||
elif [[ -n "$VideoBitrate" ]]; then
|
elif [[ -n "$VideoBitrate" ]]; then
|
||||||
echo '-b:v' "$VideoBitrate"
|
echo '-b:v' "$VideoBitrate"
|
||||||
else
|
else
|
||||||
echo "You must set ConstantRateFactor or VideoBitrate in ffmpeg.conf"
|
|
||||||
exit "$SETTINGS_ERROR"
|
exit "$SETTINGS_ERROR"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -2,5 +2,4 @@ VideoCodec="libx265"
|
|||||||
Preset="slow"
|
Preset="slow"
|
||||||
PixelFormat="yuv420p10le"
|
PixelFormat="yuv420p10le"
|
||||||
ConstantRateFactor="16"
|
ConstantRateFactor="16"
|
||||||
VideoBitrate=""
|
|
||||||
x265params="limit-sao=1:bframes=8:psy-rd=1:aq-mode=3"
|
x265params="limit-sao=1:bframes=8:psy-rd=1:aq-mode=3"
|
||||||
|
@ -7,7 +7,6 @@ Process="cudnn"
|
|||||||
GpuNum="0"
|
GpuNum="0"
|
||||||
ScaleRatio="3"
|
ScaleRatio="3"
|
||||||
OutputDepth="16"
|
OutputDepth="16"
|
||||||
Mode="noise_scale"
|
|
||||||
CropSize="256"
|
CropSize="256"
|
||||||
BatchSize="1"
|
BatchSize="1"
|
||||||
Model="upresnet10"
|
Model="upresnet10"
|
||||||
|
47
video2d-2x
47
video2d-2x
@ -19,41 +19,13 @@
|
|||||||
# 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/>.
|
||||||
|
|
||||||
|
set -Eeuo pipefail
|
||||||
|
|
||||||
readonly ScriptName=$(basename "$0")
|
readonly ScriptName=$(basename "$0")
|
||||||
readonly ScriptVersion="0.1"
|
readonly ScriptVersion="0.2"
|
||||||
readonly BaseDir=$(dirname $(readlink -e "$0"))
|
readonly BaseDir=$(dirname $(readlink -e "$0"))
|
||||||
|
|
||||||
readonly DepsDir="$BaseDir/dependencies"
|
source "$BaseDir/scripts/common.lib"
|
||||||
readonly ScriptsDir="$BaseDir/scripts"
|
|
||||||
readonly SettingsDir="$BaseDir/settings"
|
|
||||||
readonly OutputDir="$BaseDir/output"
|
|
||||||
|
|
||||||
readonly FramesDir="$OutputDir/frames"
|
|
||||||
readonly AudioDir="$OutputDir/audio"
|
|
||||||
readonly VideoDir="$OutputDir/video"
|
|
||||||
readonly SubtitlesDir="$OutputDir/subtitles"
|
|
||||||
readonly ChaptersDir="$OutputDir/chapters"
|
|
||||||
readonly AttachmentsDir="$OutputDir/attachments"
|
|
||||||
readonly ReleaseDir="$OutputDir/release"
|
|
||||||
|
|
||||||
readonly FramesUpscaledDir="${FramesDir}_upscaled"
|
|
||||||
readonly VideoUpscaledDir="${VideoDir}_upscaled"
|
|
||||||
|
|
||||||
readonly FormatJson="$OutputDir/format.json"
|
|
||||||
readonly StreamsJson="$OutputDir/streams.json"
|
|
||||||
readonly ChaptersJson="$OutputDir/chapters.json"
|
|
||||||
|
|
||||||
readonly RangesList="$OutputDir/ranges.list"
|
|
||||||
|
|
||||||
readonly Video2d2xConf="$SettingsDir/video2d-2x.conf"
|
|
||||||
readonly Waifu2xConf="$SettingsDir/waifu2x-caffe.conf"
|
|
||||||
readonly FfmpegConf="$SettingsDir/ffmpeg.conf"
|
|
||||||
readonly RangeGenConf="$SettingsDir/range-gen.conf"
|
|
||||||
|
|
||||||
source "$ScriptsDir/returncodes.lib"
|
|
||||||
source "$ScriptsDir/common.lib"
|
|
||||||
|
|
||||||
source "$Video2d2xConf"
|
|
||||||
|
|
||||||
function show_version ()
|
function show_version ()
|
||||||
{
|
{
|
||||||
@ -73,16 +45,6 @@ function show_help ()
|
|||||||
echo " -h, --help show help"
|
echo " -h, --help show help"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ -n "$Waifu2xCaffeDir" ]]; then
|
|
||||||
PATH="$PATH:$(readlink -e $Waifu2xCaffeDir)"
|
|
||||||
fi
|
|
||||||
if [[ -n "$MkvToolNixDir" ]]; then
|
|
||||||
PATH="$PATH:$(readlink -e $MkvToolNixDir)"
|
|
||||||
fi
|
|
||||||
if [[ -n "$FfmpegDir" ]]; then
|
|
||||||
PATH="$PATH:$(readlink -e $FfmpegDir)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $# -eq 0 ]]; then show_help; exit 0; fi
|
if [[ $# -eq 0 ]]; then show_help; exit 0; fi
|
||||||
case $1 in
|
case $1 in
|
||||||
-h|--help ) show_help ;;
|
-h|--help ) show_help ;;
|
||||||
@ -90,6 +52,7 @@ case $1 in
|
|||||||
-e|--extract ) shift; source "$ScriptsDir/extract.sh" ;;
|
-e|--extract ) shift; source "$ScriptsDir/extract.sh" ;;
|
||||||
-f|--frames ) shift; source "$ScriptsDir/frames.sh" ;;
|
-f|--frames ) shift; source "$ScriptsDir/frames.sh" ;;
|
||||||
-r|--ranges ) shift; source "$ScriptsDir/ranges.sh" ;;
|
-r|--ranges ) shift; source "$ScriptsDir/ranges.sh" ;;
|
||||||
|
-p|--preview ) shift; source "$ScriptsDir/preview.sh" ;;
|
||||||
-u|--upscale ) shift; source "$ScriptsDir/upscale.sh" ;;
|
-u|--upscale ) shift; source "$ScriptsDir/upscale.sh" ;;
|
||||||
-v|--video ) shift; source "$ScriptsDir/video.sh" ;;
|
-v|--video ) shift; source "$ScriptsDir/video.sh" ;;
|
||||||
-m|--merge ) shift; source "$ScriptsDir/merge.sh" ;;
|
-m|--merge ) shift; source "$ScriptsDir/merge.sh" ;;
|
||||||
|
Loading…
Reference in New Issue
Block a user