Set WebP to lossless, quality for lossy

This commit is contained in:
Stian Lund 2023-08-18 14:46:05 +02:00
parent 703f10f8e3
commit e6a8eada96

View File

@ -20,6 +20,7 @@ SET "mode="
SET "dither=" SET "dither="
SET "bayerscale=" SET "bayerscale="
SET "start_time=" SET "start_time="
SET "webp_lossy="
SET "duration=" SET "duration="
SET "colormax=" SET "colormax="
SET "version=" SET "version="
@ -56,28 +57,31 @@ ECHO Usage:
ECHO vid2ani [input_file] [Arguments] ECHO vid2ani [input_file] [Arguments]
ECHO: ECHO:
ECHO Arguments: ECHO Arguments:
ECHO -t Specifies output filetype: gif, png, webp. ECHO -t Output filetype: gif, png, webp.
ECHO The default is gif. ECHO The default is gif.
ECHO -o Specifies output filename. ECHO -o Output filename.
ECHO Will be output to the same directory as your input video. ECHO Will be output to the same directory as your input video.
ECHO The default is the same as the input video. ECHO The default is the same as the input video.
ECHO -r Specifies scale or size. ECHO -r Scale or size.
ECHO Width of the animation in pixels. ECHO Width of the animation in pixels.
ECHO The default is the same scale as the original video. ECHO The default is the same scale as the original video.
ECHO -f Specifies framerate in frames per second. ECHO -f Framerate in frames per second.
ECHO The default is 15. ECHO The default is 15.
ECHO -m Specifies one of the 3 modes listed below. ECHO -m Palettegen mode - one of 3 modes listed below.
ECHO The default is diff. ECHO The default is diff.
ECHO -d Specifies which dithering algorithm to be used. ECHO -d Dithering algorithm to be used.
ECHO The default is 1 (Bayer). ECHO The default is 1 (Bayer).
ECHO -b Specifies the Bayer Scale. (Optional) ECHO -b Bayer Scale setting. (Optional)
ECHO This can only be used when Bayer dithering is applied. ECHO This can only be used when Bayer dithering is applied.
ECHO See more information below. ECHO See more information below.
ECHO -s Specifies the start of the animation in HH:MM:SS.MS format. ECHO -l Set lossy WebP compression and quality
ECHO Value 0-100, default 75.
ECHO (Webp default is lossless)
ECHO -s Start of the animation in HH:MM:SS.MS format.
ECHO (Optional) ECHO (Optional)
ECHO -e Specifies the duration of the animation in seconds. ECHO -e Duration of the animation in seconds.
ECHO (Optional) ECHO (Optional)
ECHO -c Sets the maximum amount of colors useable per palette. ECHO -c The maximum amount of colors useable per palette.
ECHO (Optional value up to 256) ECHO (Optional value up to 256)
ECHO This option isn't used by default. ECHO This option isn't used by default.
ECHO -k Enables error diffusion. ECHO -k Enables error diffusion.
@ -116,6 +120,45 @@ ECHO would not be possible. Thank you all for your contributions and
ECHO assistance^^! ECHO assistance^^!
GOTO :EOF GOTO :EOF
:help_check_1
IF %input% == "" GOTO :help_message
IF %input% == "help" GOTO :help_message
IF %input% == "-?" GOTO :help_message
IF %input% == "--help" GOTO :help_message
GOTO :varin
:: Checking for blank input or help commands
:varin
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=%~dpnx2" & SHIFT
IF "%~1" =="-s" SET "start_time=%~2" & SHIFT
IF "%~1" =="-e" SET "duration=%~2" & SHIFT
IF "%~1" =="-c" SET "colormax=%~2" & SHIFT
IF "%~1" =="-l" SET "webp_lossy=%~2" & SHIFT
IF "%~1" =="-k" SET "errorswitch=0"
IF "%~1" =="-p" SET "picswitch=0"
SHIFT & GOTO :varin
)
GOTO :help_check_2
:: Using SHIFT command to go through the input and storing each setting into its own variable
:help_check_2
IF NOT DEFINED filetype SET "filetype=gif"
IF NOT DEFINED scale SET "scale=-1"
IF NOT DEFINED fps SET fps=15
IF NOT DEFINED mode SET mode=1
IF NOT DEFINED dither SET dither=1
GOTO :safchek
:: Noob proofing the script to prevent it from breaking should critical settings not be defined
:safchek :safchek
echo %filetype% | findstr /r "\<gif\> \<png\> \<apng\> \<webp\>" >nul echo %filetype% | findstr /r "\<gif\> \<png\> \<apng\> \<webp\>" >nul
IF %errorlevel% NEQ 0 ( IF %errorlevel% NEQ 0 (
@ -130,6 +173,7 @@ IF %mode% GTR 3 (
ECHO Not a valid mode ECHO Not a valid mode
GOTO :EOF GOTO :EOF
) )
IF %dither% GTR 8 ( IF %dither% GTR 8 (
ECHO Not a valid dither algorithm ECHO Not a valid dither algorithm
GOTO :EOF GOTO :EOF
@ -137,6 +181,20 @@ IF %dither% GTR 8 (
ECHO Not a valid dither algorithm ECHO Not a valid dither algorithm
GOTO :EOF GOTO :EOF
) )
IF DEFINED webp_lossy (
IF NOT "%filetype%" == "webp" (
ECHO Lossy is only valid for filetype webp
GOTO :EOF
) ELSE IF !webp_lossy! GTR 100 (
ECHO Not a valid lossy quality value
GOTO :EOF
) ELSE IF !webp_lossy! LSS 0 (
ECHO Not a valid lossy quality value
GOTO :EOF
)
)
IF DEFINED bayerscale ( IF DEFINED bayerscale (
IF !bayerscale! GTR 5 ( IF !bayerscale! GTR 5 (
ECHO Not a valid bayerscale value ECHO Not a valid bayerscale value
@ -156,42 +214,6 @@ IF DEFINED bayerscale (
GOTO :script_start GOTO :script_start
:: Setting a clear range of acceptable setting values and noob proofing bayerscale :: Setting a clear range of acceptable setting values and noob proofing bayerscale
:varin
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=%~dpnx2" & SHIFT
IF "%~1" =="-s" SET "start_time=%~2" & SHIFT
IF "%~1" =="-e" SET "duration=%~2" & SHIFT
IF "%~1" =="-c" SET "colormax=%~2" & SHIFT
IF "%~1" =="-k" SET "errorswitch=0"
IF "%~1" =="-p" SET "picswitch=0"
SHIFT & GOTO :varin
)
GOTO :help_check_2
:: Using SHIFT command to go through the input and storing each setting into its own variable
:help_check_1
IF %input% == "" GOTO :help_message
IF %input% == "help" GOTO :help_message
IF %input% == "h" GOTO :help_message
IF %input% == "-h" GOTO :help_message
GOTO :varin
:: Checking for blank input or help commands
:help_check_2
IF NOT DEFINED filetype SET "filetype=gif"
IF NOT DEFINED scale SET "scale=-1"
IF NOT DEFINED fps SET fps=15
IF NOT DEFINED mode SET mode=1
IF NOT DEFINED dither SET dither=1
GOTO :safchek
:: Noob proofing the script to prevent it from breaking should critical settings not be defined
:script_start :script_start
IF "%filetype%"=="png" SET filetype=apng IF "%filetype%"=="png" SET filetype=apng
IF "%filetype%"=="apng" SET output=%output%.png IF "%filetype%"=="apng" SET output=%output%.png
@ -257,6 +279,12 @@ IF DEFINED errorswitch (
IF %mode% EQU 3 SET "errordiff==diff_mode=rectangle" IF %mode% EQU 3 SET "errordiff==diff_mode=rectangle"
) )
IF "%filetype%" == "webp" (
IF DEFINED webp_lossy (
SET "webp_lossy=-lossless 0 -quality %webp_lossy%"
) ELSE SET "webp_lossy=-lossless 1"
)
IF %dither% EQU 0 SET ditheralg=none IF %dither% EQU 0 SET ditheralg=none
IF %dither% EQU 1 SET ditheralg=bayer IF %dither% EQU 1 SET ditheralg=bayer
IF %dither% EQU 2 SET ditheralg=heckbert IF %dither% EQU 2 SET ditheralg=heckbert
@ -270,7 +298,7 @@ IF %dither% EQU 8 SET ditheralg=atkinson
IF NOT %mode% EQU 2 ( IF NOT %mode% EQU 2 (
IF DEFINED errorswitch SET ditherenc=:dither=!ditheralg! IF DEFINED errorswitch SET ditherenc=:dither=!ditheralg!
IF NOT DEFINED errorswitch SET ditherenc==dither=!ditheralg! IF NOT DEFINED errorswitch SET ditherenc==dither=!ditheralg!
)else SET ditherenc=:dither=!ditheralg! ) ELSE SET ditherenc=:dither=!ditheralg!
:: Setting variables to put the command together; checking for Error Diffusion if using Bayer Scale and adjusting the command accordingly :: Setting variables to put the command together; checking for Error Diffusion if using Bayer Scale and adjusting the command accordingly
IF NOT DEFINED bayerscale SET "bayer=" IF NOT DEFINED bayerscale SET "bayer="