Change to use color variables for readability

This commit is contained in:
2024-12-28 17:21:37 +01:00
parent 04384fac45
commit a262673f05
+61 -51
View File
@@ -9,6 +9,13 @@
:: Enable delayed variable expension
SETLOCAL ENABLEDELAYEDEXPANSION
:: Colors
SET OFF=
SET GREEN=
SET YELLOW=
SET RED=
SET CYAN=
:: Storing Paths
SET input="%~1"
SET vid="%~dpnx1"
@@ -79,7 +86,7 @@ GOTO :safchek
:: Output file type
echo %filetype% | findstr /r "\<gif\> \<png\> \<apng\> \<webp\>" >nul
IF %errorlevel% NEQ 0 (
ECHO Not a valid file type
ECHO %RED%Not a valid file type: %filetype%%OFF%
GOTO :EOF
)
IF "%filetype%"=="png" SET filetype=apng
@@ -89,33 +96,33 @@ IF "%filetype%"=="gif" SET output=%output%.gif
:: Palettegen
IF %mode% GTR 3 (
ECHO Not a valid palettegen mode
ECHO %RED%Not a valid palettegen mode%OFF%
GOTO :EOF
) ELSE IF %mode% LSS 1 (
ECHO Not a valid palettegen mode
ECHO %RED%Not a valid palettegen mode%OFF%
GOTO :EOF
)
:: Dithering
IF %dither% GTR 8 (
ECHO Not a valid dither algorithm
ECHO %RED%Not a valid dither algorithm%OFF%
GOTO :EOF
) ELSE IF %dither% LSS 0 (
ECHO Not a valid dither algorithm
ECHO %RED%Not a valid dither algorithm%OFF%
GOTO :EOF
)
:: Bayerscale
IF DEFINED bayerscale (
IF !bayerscale! GTR 5 (
ECHO Not a valid bayerscale value
ECHO %RED%Not a valid bayerscale value%OFF%
GOTO :EOF
) ELSE IF !bayerscale! LSS 0 (
ECHO Not a valid bayerscale value
ECHO %RED%Not a valid bayerscale value%OFF%
GOTO :EOF
)
IF !bayerscale! LEQ 5 (
IF %dither% NEQ 1 (
ECHO This setting only works with bayer dithering
ECHO %RED%This setting only works with bayer dithering%OFF%
GOTO :EOF
)
)
@@ -124,13 +131,13 @@ IF DEFINED bayerscale (
:: Lossy WEBP
IF DEFINED webp_lossy (
IF NOT "%filetype%" == "webp" (
ECHO Lossy is only valid for filetype webp
ECHO %RED%Lossy is only valid for filetype webp%OFF%
GOTO :EOF
) ELSE IF !webp_lossy! GTR 100 (
ECHO Not a valid lossy quality value
ECHO %RED%Not a valid lossy quality value%OFF%
GOTO :EOF
) ELSE IF !webp_lossy! LSS 0 (
ECHO Not a valid lossy quality value
ECHO %RED%Not a valid lossy quality value%OFF%
GOTO :EOF
)
)
@@ -139,14 +146,14 @@ IF DEFINED webp_lossy (
IF DEFINED start_time (
IF DEFINED end_time SET "trim=-ss !start_time! -to !end_time!"
IF NOT DEFINED end_time (
ECHO Please input the end time
ECHO %RED%Please input the end time%OFF%
GOTO :EOF
)
)
IF NOT DEFINED start_time (
IF DEFINED end_time (
ECHO Please input the start time
ECHO %RED%Please input the start time%OFF%
GOTO :EOF
)
)
@@ -163,10 +170,10 @@ FOR /F "delims=" %%a in ('ffmpeg -version') DO (
)
:: Displaying FFmpeg version string and creating the working directory
ECHO %version%
ECHO %build%
ECHO Output file: %output%
ECHO Creating working directory...
ECHO %YELLOW%%version%%OFF%
ECHO %YELLOW%%build%%OFF%
ECHO %GREEN%Output file:%OFF% %output%
ECHO %GREEN%Creating working directory...%OFF%
MD "%WD%"
:palettegen
@@ -187,13 +194,14 @@ IF DEFINED colormax (
)
:: Executing command to generate palette
ECHO Generating palette...
ECHO %GREEN%Generating palette...%OFF%
echo ffmpeg -v %loglevel% %trim% -i %vid% -vf "%filters%,%encode%%mcol%" -y "%frames%.png"
ffmpeg -v %loglevel% %trim% -i %vid% -vf "%filters%,%encode%%mcol%" -y "%frames%.png"
:: Checking if the palette file is in the Working Directory, if not cleaning up
IF NOT EXIST "%palette%_00001.png" (
IF NOT EXIST "%palette%.png" (
ECHO Failed to generate palette file
ECHO %RED%Failed to generate palette file%OFF%
GOTO :cleanup
)
)
@@ -239,12 +247,13 @@ IF NOT DEFINED bayerscale SET "bayer="
IF DEFINED bayerscale SET bayer=:bayer_scale=%bayerscale%
:: Executing the encoding command
ECHO Encoding animation...
ECHO %GREEN%Encoding animation...%OFF%
echo ffmpeg -v %loglevel% %trim% -i %vid% -thread_queue_size 512 -i "%frames%.png" -lavfi "%filters% [x]; [x][1:v] %decode%%errordiff%%ditherenc%%bayer%" -f %filetype% %webp_lossy% -loop 0 -plays 0 -y "%output%"
ffmpeg -v %loglevel% %trim% -i %vid% -thread_queue_size 512 -i "%frames%.png" -lavfi "%filters% [x]; [x][1:v] %decode%%errordiff%%ditherenc%%bayer%" -f %filetype% %webp_lossy% -loop 0 -plays 0 -y "%output%"
:: Checking if file was created and cleaning up if not
IF NOT EXIST "%output%" (
ECHO Failed to generate animation
ECHO %RED%Failed to generate animation%OFF%
GOTO :cleanup
)
@@ -253,74 +262,75 @@ IF DEFINED picswitch START "" "%output%"
:cleanup
:: Cleaning up
ECHO Deleting temporary files...
ECHO %GREEN%Deleting temporary files...%OFF%
RMDIR /S /Q "%WD%"
ECHO %YELLOW%Done.%OFF%
ENDLOCAL
ECHO Done!
GOTO :EOF
:help_message
:: Print usage message
ECHO:
ECHO Video to GIF/APNG/WEBP converter v6.0
ECHO By MDHEXT, Nabi KaramAliZadeh, Pathduck
ECHO %GREEN%Video to GIF/APNG/WEBP converter v6.0%OFF%
ECHO %CYAN%By MDHEXT, Nabi KaramAliZadeh, Pathduck%OFF%
ECHO:
ECHO You can download this fork from here:
ECHO https://github.com/Pathduck/vid2ani/
ECHO You can download this fork from here:
ECHO %CYAN%https://github.com/Pathduck/vid2ani/%OFF%
ECHO You can download the original release here:
ECHO https://github.com/NabiKAZ/video2gif
ECHO %CYAN%https://github.com/NabiKAZ/video2gif%OFF%
ECHO This tool uses ffmpeg, you can download that here:
ECHO https://www.ffmpeg.org/download.html#build-windows
ECHO %CYAN%https://www.ffmpeg.org/download.html%OFF%
ECHO This tool wouldn't be possible without the research listed here:
ECHO https://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
ECHO %CYAN%https://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html%OFF%
ECHO:
ECHO Usage:
ECHO %GREEN%Usage:%OFF%
ECHO vid2ani [input_file] [Arguments]
ECHO:
ECHO Arguments:
ECHO %GREEN%Arguments:%OFF%
ECHO:
ECHO -t Output file type.
ECHO Valid: 'gif' (default), 'png', 'webp'.
ECHO %YELLOW%Valid: 'gif' (default), 'png', 'webp'.%OFF%
ECHO:
ECHO -o Output file.
ECHO The default is the same name as the input video.
ECHO %YELLOW%The default is the same name as the input video.%OFF%
ECHO:
ECHO -r Scale or size.
ECHO Width of the animation in pixels.
ECHO The default is the same scale as the original video.
ECHO %CYAN%Width of the animation in pixels.%OFF%
ECHO %YELLOW%The default is the same scale as the original video.%OFF%
ECHO:
ECHO -s Start time of the animation (HH:MM:SS.MS)
ECHO -s Start time of the animation %CYAN%(HH:MM:SS.MS)%OFF%
ECHO:
ECHO -e End time of the animation (HH:MM:SS.MS)
ECHO -e End time of the animation %CYAN%(HH:MM:SS.MS)%OFF%
ECHO:
ECHO -f Framerate in frames per second.
ECHO The default is 15.
ECHO %YELLOW%The default is 15.%OFF%
ECHO:
ECHO -d Dithering algorithm to be used.
ECHO The default is 0 (None).
ECHO %YELLOW%The default is 0 (None).%OFF%
ECHO:
ECHO -b Bayer Scale setting.
ECHO This can only be used when Bayer dithering is applied.
ECHO Range 0 - 5, default is 2.
ECHO %CYAN%This can only be used when Bayer dithering is applied.
ECHO %YELLOW%Range 0 - 5, default is 2.%OFF%
ECHO:
ECHO -m Palettegen mode - one of 3 modes listed below.
ECHO The default is 1 (diff).
ECHO %YELLOW%The default is 1 (diff).%OFF%
ECHO:
ECHO -c The maximum amount of colors useable per palette.
ECHO Range 3 - 256 (default)
ECHO %YELLOW%Range 3 - 256 (default)%OFF%
ECHO:
ECHO -k Enables paletteuse error diffusion.
ECHO:
ECHO -l Enable lossy WebP compression and quality.
ECHO The default for WebP is lossless.
ECHO Range 0 - 100, default 75.
ECHO %CYAN%The default for WebP is lossless.%OFF%
ECHO %YELLOW%Range 0 - 100, default 75.%OFF%
ECHO:
ECHO -v Set FFmpeg log level, for troubleshooting.
ECHO The default log level is 'error'
ECHO %YELLOW%The default log level is 'error'%OFF%
ECHO:
ECHO -p Opens the resulting animation in your default Photo Viewer.
ECHO:
ECHO Dithering Modes:
ECHO %GREEN%Dithering Mode%OFF%
ECHO 0: None
ECHO 1: Bayer
ECHO 2: Heckbert
@@ -331,18 +341,18 @@ ECHO 6: Sierra3
ECHO 7: Burkes
ECHO 8: Atkinson
ECHO:
ECHO Palettegen Modes:
ECHO %GREEN%Palettegen Modes%OFF%
ECHO 1: diff - only what moves affects the palette
ECHO 2: single - one palette per frame
ECHO 3: full - one palette for the whole animation
ECHO:
ECHO About Bayerscale:
ECHO %GREEN%About Bayerscale%OFF%
ECHO When bayer dithering is selected, the Bayer Scale option defines the
ECHO scale of the pattern (how much the crosshatch pattern is visible).
ECHO A low value means more visible pattern for less banding, a higher value
ECHO means less visible pattern at the cost of more banding.
ECHO:
ECHO People who made this project come to fruition:
ECHO %GREEN%People who made this project come to fruition%OFF%
ECHO ubitux, Nabi KaramAliZadeh, and the very kind and patient people in the
ECHO Batch Discord Server. Without these people's contributions, this script
ECHO would not be possible. Thank you all for your contributions and