Update files

This commit is contained in:
Stian 2025-01-06 13:20:10 +01:00
parent 0ac0b2679c
commit 5f4ac035cb
2 changed files with 103 additions and 109 deletions

View File

@ -11,13 +11,32 @@ SETLOCAL ENABLEDELAYEDEXPANSION
:: Define ANSI Colors
SET "OFF="
SET "RED="
SET "RED="
SET "GREEN="
SET "YELLOW="
SET "BLUE="
SET "CYAN="
:: Clearing vars and setting defaults
:: Checking for blank input or help commands
IF "%~1" == "" GOTO :help_message
IF "%~1" == "-?" GOTO :help_message
IF "%~1" == "/?" GOTO :help_message
IF "%~1" == "--help" GOTO :help_message
:: Assign input and output
SET input="%~1"
SET output=%~dpn1
:: Validate input file
IF NOT EXIST %input% (
ECHO %RED%Input file not found: %input%%OFF%
GOTO :EOF
)
:: Setting the path to the working directory
SET WD=%TEMP%\VID2ANI
:: Clearing input vars and setting defaults
SET "fps=15"
SET "mode=1"
SET "dither=0"
@ -30,51 +49,28 @@ SET "bayerscale="
SET "colormax="
SET "start_time="
SET "end_time="
SET "version="
SET "build="
SET "errorswitch="
SET "picswitch="
:: Assign input and output
SET input="%~1"
SET output=%~dpn1
:: Input file validation
IF NOT EXIST %input% (
ECHO %RED%Input file not found: %input%%OFF%
GOTO :EOF
)
:: Setting the path to the Working Directory
SET WD=%TEMP%\VID2ANI
:: Checking for blank input or help commands
IF %input% == "" GOTO :help_message
IF %input% == "-?" GOTO :help_message
IF %input% == "/?" GOTO :help_message
IF %input% == "help" GOTO :help_message
IF %input% == "--help" GOTO :help_message
GOTO :varin
:varin
:: Using SHIFT command to go through the input and storing each setting into its own variable
IF NOT "%~1" =="" (
IF "%~1" =="-r" SET "scale=%~2" & SHIFT
IF "%~1" =="-f" SET "fps=%~2" & SHIFT
IF "%~1" =="-m" SET "mode=%~2" & SHIFT
IF "%~1" =="-d" SET "dither=%~2" & SHIFT
IF "%~1" =="-b" SET "bayerscale=%~2" & SHIFT
IF "%~1" =="-t" SET "filetype=%~2" & SHIFT
IF "%~1" =="-o" SET "output=%~dpn2" & SHIFT
IF "%~1" =="-s" SET "start_time=%~2" & SHIFT
IF "%~1" =="-e" SET "end_time=%~2" & SHIFT
IF "%~1" =="-c" SET "colormax=%~2" & SHIFT
:: IF "%~1" =="-l" SET "webp_lossy=%~2" & SHIFT
IF "%~1" =="-l" (IF "%2" == "" ( SET "webp_lossy=%webp_lossy_def%"
) ELSE IF 1%2 NEQ +1%~2 ( SET "webp_lossy=%webp_lossy_def%"
IF "%~1" =="-t" SET "filetype=%~2" & SHIFT
IF "%~1" =="-r" SET "scale=%~2" & SHIFT
IF "%~1" =="-l" ( IF 1%2 NEQ +1%~2 ( SET "webp_lossy=%webp_lossy_def%"
) ELSE IF "%~2" == "" ( SET "webp_lossy=%webp_lossy_def%"
) ELSE ( SET "webp_lossy=%~2" & SHIFT )
)
IF "%~1" =="-f" SET "fps=%~2" & SHIFT
IF "%~1" =="-s" SET "start_time=%~2" & SHIFT
IF "%~1" =="-e" SET "end_time=%~2" & SHIFT
IF "%~1" =="-d" SET "dither=%~2" & SHIFT
IF "%~1" =="-b" SET "bayerscale=%~2" & SHIFT
IF "%~1" =="-m" SET "mode=%~2" & SHIFT
IF "%~1" =="-c" SET "colormax=%~2" & SHIFT
IF "%~1" =="-v" SET "loglevel=%~2" & SHIFT
IF "%~1" =="-k" SET "errorswitch=1"
IF "%~1" =="-p" SET "picswitch=1"
@ -83,8 +79,6 @@ IF NOT "%~1" =="" (
GOTO :safchek
:safchek
:: Setting a clear range of acceptable setting values and noob proofing bayerscale
:: Validate output file extension
echo %filetype% | findstr /r "\<gif\> \<png\> \<apng\> \<webp\>" >nul
IF %errorlevel% NEQ 0 (
@ -97,19 +91,19 @@ IF "%filetype%"=="apng" SET "output=%output%.png"
IF "%filetype%"=="webp" SET "output=%output%.webp"
:: Validate Palettegen
IF %mode% GTR 3 (
IF !mode! GTR 3 (
ECHO %RED%Not a valid palettegen ^(-m^) mode%OFF%
GOTO :EOF
) ELSE IF %mode% LSS 1 (
) ELSE IF !%mode! LSS 1 (
ECHO %RED%Not a valid palettegen ^(-m^) mode%OFF%
GOTO :EOF
)
:: Validate Dithering
IF %dither% GTR 8 (
IF !dither! GTR 8 (
ECHO %RED%Not a valid dither ^(-d^) algorithm %OFF%
GOTO :EOF
) ELSE IF %dither% LSS 0 (
) ELSE IF !dither! LSS 0 (
ECHO %RED%Not a valid dither ^(-d^) algorithm%OFF%
GOTO :EOF
)
@ -123,7 +117,7 @@ IF DEFINED bayerscale (
ECHO %RED%Not a valid bayerscale ^(-b^) value%OFF%
GOTO :EOF
)
IF %dither% NEQ 1 (
IF !dither! NEQ 1 (
IF !bayerscale! LEQ 5 (
ECHO %RED%Bayerscale ^(-b^) only works with Bayer dithering%OFF%
GOTO :EOF
@ -206,21 +200,21 @@ SET filters=fps=%fps%,scale=%scale%:-1:flags=lanczos
:: APNG muxer does not support multiple palettes so fallback to using palettegen diff mode
IF "%filetype%"=="apng" (
IF %mode% EQU 2 (
IF !mode! EQU 2 (
ECHO %YELLOW%APNG does not support multiple palettes - falling back to Palettegen mode 1 ^(diff^)%OFF%
SET mode=1
)
)
:: Palettegen encode mode
IF %mode% EQU 1 SET "encode=palettegen=stats_mode=diff"
IF %mode% EQU 2 SET "encode=palettegen=stats_mode=single"
IF %mode% EQU 3 SET "encode=palettegen"
IF !mode! EQU 1 SET "encode=palettegen=stats_mode=diff"
IF !mode! EQU 2 SET "encode=palettegen=stats_mode=single"
IF !mode! EQU 3 SET "encode=palettegen"
:: Max colors
IF DEFINED colormax (
IF %mode% LEQ 2 SET "mcol=:max_colors=%colormax%"
IF %mode% EQU 3 SET "mcol==max_colors=%colormax%"
IF !mode! LEQ 2 SET "mcol=:max_colors=%colormax%"
IF !mode! EQU 3 SET "mcol==max_colors=%colormax%"
)
:: Executing command to generate palette
@ -236,30 +230,30 @@ IF NOT EXIST "%WD%\palette_00001.png" (
:: Setting variables to put the encode command together
:: Palettegen decode mode
IF %mode% EQU 1 SET "decode=paletteuse"
IF %mode% EQU 2 SET "decode=paletteuse=new=1"
IF %mode% EQU 3 SET "decode=paletteuse"
IF !mode! EQU 1 SET "decode=paletteuse"
IF !mode! EQU 2 SET "decode=paletteuse=new=1"
IF !mode! EQU 3 SET "decode=paletteuse"
:: Error diffusion
IF DEFINED errorswitch (
IF %mode% EQU 1 SET "errordiff==diff_mode=rectangle"
IF %mode% EQU 2 SET "errordiff=:diff_mode=rectangle"
IF %mode% EQU 3 SET "errordiff==diff_mode=rectangle"
IF !mode! EQU 1 SET "errordiff==diff_mode=rectangle"
IF !mode! EQU 2 SET "errordiff=:diff_mode=rectangle"
IF !mode! EQU 3 SET "errordiff==diff_mode=rectangle"
)
:: Prepare dithering and encoding options
IF %dither% EQU 0 SET "ditheralg=none"
IF %dither% EQU 1 SET "ditheralg=bayer"
IF %dither% EQU 2 SET "ditheralg=heckbert"
IF %dither% EQU 3 SET "ditheralg=floyd_steinberg"
IF %dither% EQU 4 SET "ditheralg=sierra2"
IF %dither% EQU 5 SET "ditheralg=sierra2_4a"
IF %dither% EQU 6 SET "ditheralg=sierra3"
IF %dither% EQU 7 SET "ditheralg=burkes"
IF %dither% EQU 8 SET "ditheralg=atkinson"
IF !dither! EQU 0 SET "ditheralg=none"
IF !dither! EQU 1 SET "ditheralg=bayer"
IF !dither! EQU 2 SET "ditheralg=heckbert"
IF !dither! EQU 3 SET "ditheralg=floyd_steinberg"
IF !dither! EQU 4 SET "ditheralg=sierra2"
IF !dither! EQU 5 SET "ditheralg=sierra2_4a"
IF !dither! EQU 6 SET "ditheralg=sierra3"
IF !dither! EQU 7 SET "ditheralg=burkes"
IF !dither! EQU 8 SET "ditheralg=atkinson"
:: Paletteuse error diffusion
IF NOT %mode% EQU 2 (
IF NOT !mode! EQU 2 (
IF DEFINED errorswitch SET "ditherenc=:dither=!ditheralg!"
IF NOT DEFINED errorswitch SET "ditherenc==dither=!ditheralg!"
) ELSE SET "ditherenc=:dither=!ditheralg!"
@ -318,7 +312,7 @@ ECHO -b Bayer Scale setting. Range 0-5, default 2.
ECHO -m Palettegen mode: 1 (diff), 2 (single), 3 (full), default 1.
ECHO -c Maximum colors usable per palette. Range 3-256 (default).
ECHO -k Enables paletteuse error diffusion.
ECHO -p Opens the resulting animation in the sysem image viewer.
ECHO -p Opens the resulting animation in the system image viewer.
ECHO -v Set FFmpeg log level (default: error).
ECHO:
ECHO %GREEN%Dithering Algorithms%OFF%

View File

@ -20,35 +20,24 @@ YELLOW=$(tput setaf 11)
BLUE=$(tput setaf 12)
CYAN=$(tput setaf 14)
# Clearing vars and setting defaults
fps=15
mode=1
dither=0
scale="-1"
filetype="gif"
webp_lossy=""
webp_lossy_def=75
loglevel="error"
bayerscale=""
colormax=""
start_time=""
end_time=""
trim=""
errorswitch=""
errordiff=""
picswitch=""
# Checking for blank input or help commands
if [ $# -eq 0 ]; then print_help; exit; fi
case "$1" in
-h) print_help; exit;;
-?) print_help; exit;;
--help) print_help; exit;;
esac
# Assign input and output
if [ $# -eq 0 ]; then print_help; exit; fi
input="$1"
output="${input%.*}"
# Input file validation
# Validate input file
if [[ ! -f "$input" ]]; then
echo ${RED}"Input file not found: $input"${OFF}; exit 1
fi
# Fix paths for Cygwin and create working dir
# Fix paths for Cygwin and create working directory
if [[ "$(uname -o)" == "Cygwin" ]]; then
# Use Windows-compatible directories for Cygwin
input=$(cygpath -w "$input")
@ -62,29 +51,44 @@ fi
# Cleanup on exit, interrupt, termination
trap 'rm -rf "$WD"' EXIT INT TERM
# Clearing input vars and setting defaults
fps=15
mode=1
dither=0
scale="-1"
filetype="gif"
webp_lossy=""
webp_lossy_def=75
loglevel="error"
bayerscale=""
colormax=""
start_time=""
end_time=""
errorswitch=""
picswitch=""
# Parse Arguments
shift
while [[ $# -gt 0 ]]; do
case "$1" in
-r) scale="$2"; shift 2;;
-f) fps="$2"; shift 2;;
-m) mode="$2"; shift 2;;
-d) dither="$2"; shift 2;;
-b) bayerscale="$2"; shift 2;;
-t) filetype="$2"; shift 2;;
-o) output="${2%.*}"; shift 2;;
-s) start_time="$2"; shift 2;;
-e) end_time="$2"; shift 2;;
-c) colormax="$2"; shift 2;;
# -l) webp_lossy="$2"; shift 2;;
-l) if [[ ! "$2" =~ ^[0-9]+$ ]]; then webp_lossy=$webp_lossy_def; shift
else webp_lossy="$2"; shift 2; fi ;;
-v) loglevel="$2"; shift 2;;
-k) errorswitch=1; shift;;
-p) picswitch=1; shift;;
-h|-?) print_help; exit;;
-o) output="${2%.*}"; shift;;
-t) filetype="$2"; shift;;
-r) scale="$2"; shift;;
-l) if [[ "$2" =~ ^[0-9]+$ ]]; then webp_lossy="$2"; shift
else webp_lossy=$webp_lossy_def; fi ;;
-f) fps="$2"; shift;;
-s) start_time="$2"; shift;;
-e) end_time="$2"; shift;;
-d) dither="$2"; shift;;
-b) bayerscale="$2"; shift;;
-m) mode="$2"; shift;;
-c) colormax="$2"; shift;;
-v) loglevel="$2"; shift;;
-k) errorswitch=1;;
-p) picswitch=1;;
*) echo ${RED}"Unknown option $1"${OFF}; exit 1;;
esac
shift
done
# Validate output file extension
@ -161,7 +165,6 @@ if [[ "$filetype" == "apng" && "$mode" -eq 2 ]]; then
fi
# Palettegen encode mode
encode=""
if [[ -n "$mode" ]]; then
case "$mode" in
1) encode="palettegen=stats_mode=diff";;
@ -172,7 +175,6 @@ if [[ -n "$mode" ]]; then
fi
# Max colors
mcol=""
if [[ -n "$colormax" ]]; then
if [[ "$mode" -le 2 ]]; then mcol=":max_colors=${colormax}"; fi
if [[ "$mode" -eq 3 ]]; then mcol="=max_colors=${colormax}"; fi
@ -210,7 +212,6 @@ if [[ -n "$errorswitch" ]]; then
fi
# Prepare dithering and encoding options
ditheralg="none"
case "$dither" in
0) ditheralg="none";;
1) ditheralg="bayer";;
@ -221,11 +222,10 @@ case "$dither" in
6) ditheralg="sierra3";;
7) ditheralg="burkes";;
8) ditheralg="atkinson";;
*) echo ${RED}"Invalid dither (-d )mode"${OFF}; exit 1;;
*) echo ${RED}"Invalid dither (-d ) mode"${OFF}; exit 1;;
esac
# Paletteuse error diffusion
ditherenc=""
if [[ "$mode" -ne 2 ]]; then
if [[ -n "$errorswitch" ]]; then ditherenc=":dither=$ditheralg"; fi
if [[ -z "$errorswitch" ]]; then ditherenc="=dither=$ditheralg"; fi
@ -285,7 +285,7 @@ ${GREEN}Arguments:${OFF}
-m Palettegen mode: 1 (diff), 2 (single), 3 (full), default 1.
-c Maximum colors usable per palette. Range 3-256 (default).
-k Enables paletteuse error diffusion.
-p Opens the resulting animation in the sysem image viewer.
-p Opens the resulting animation in the system image viewer.
-v Set FFmpeg log level (default: error).
${GREEN}Dithering Algorithms${OFF}