1
0
This commit is contained in:
2024-11-14 18:01:19 +01:00
parent 0ecc0ad6a3
commit f94d01298f

View File

@@ -15,123 +15,31 @@ SET vid="%~dpnx1"
SET output=%~dpn1
SET FILEPATH=%~dp1
:: 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
:: Clearing all variables
SET "filetype="
SET "scale="
SET "fps="
SET "mode="
SET "dither="
SET "bayerscale="
SET "filetype="
SET "start_time="
SET "end_time="
SET "webp_lossy="
SET "colormax="
SET "version="
SET "build="
SET "loglevel="
:: Setting the path to the Working Directory
SET WD=%TEMP%\VID2ANI
:: Palette filename
SET palette=%WD%\palette
:: Storing FFmpeg version string
FOR /F "delims=" %%a in ('ffmpeg -version') DO (
IF NOT DEFINED version (
SET "version=%%a"
) ELSE IF NOT DEFINED build (
SET "build=%%a"
)
)
GOTO :help_check_1
:help_message
:: Print usage message
ECHO:
ECHO Video to GIF/APNG/WEBP converter v5.5
ECHO ^(C^) 2017-2022, MDHEXT ^&^ Nabi KaramAliZadeh ^<nabikaz@gmail.com^>
ECHO:
ECHO You can download this fork from here:
ECHO https://github.com/MDHEXT/video2gif
ECHO You can download the original release here:
ECHO https://github.com/NabiKAZ/video2gif
ECHO This tool uses ffmpeg, you can download that here:
ECHO https://www.ffmpeg.org/download.html#build-windows
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:
ECHO Usage:
ECHO vid2ani [input_file] [Arguments]
ECHO:
ECHO Arguments:
ECHO -t Output filetype: gif, png, webp.
ECHO The default is gif.
ECHO -o Output file.
ECHO The default is the same name as the input video.
ECHO -r Scale or size.
ECHO Width of the animation in pixels.
ECHO The default is the same scale as the original video.
ECHO -f Framerate in frames per second.
ECHO The default is 15.
ECHO -m Palettegen mode - one of 3 modes listed below.
ECHO The default is 1 (diff).
ECHO -d Dithering algorithm to be used.
ECHO The default is 0 (None).
ECHO -b Bayer Scale setting. (Optional)
ECHO This can only be used when Bayer dithering is applied.
ECHO See more information below.
ECHO -l Set lossy WebP compression and quality
ECHO Value 0-100, default 75.
ECHO (Default for WebP is lossless)
ECHO -c The maximum amount of colors useable per palette.
ECHO (Optional value up to 256)
ECHO This option isn't used by default.
ECHO -s Start time of the animation (HH:MM:SS.MS)
ECHO (Optional)
ECHO -e End time of the animation (HH:MM:SS.MS)
ECHO (Optional)
ECHO -k Enables error diffusion.
ECHO (Optional)
ECHO -p Opens the resulting animation in your default Photo Viewer.
ECHO (Optional)
ECHO:
ECHO Palettegen Modes:
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 Dithering Options:
ECHO 0: None
ECHO 1: Bayer
ECHO 2: Heckbert
ECHO 3: Floyd Steinberg
ECHO 4: Sierra2
ECHO 5: Sierra2_4a
ECHO 6: sierra3
ECHO 7: burkes
ECHO 8: atkinson
ECHO:
ECHO About Bayerscale:
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 The option must be an integer value in the range [0,5].
ECHO The Default is 2. Bayer Scale is optional.
ECHO:
ECHO People who made this project come to fruition:
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
ECHO assistance^^!
GOTO :EOF
:help_check_1
:: Checking for blank input or help commands
IF %input% == "" GOTO :help_message
IF %input% == "help" GOTO :help_message
IF %input% == "-?" GOTO :help_message
IF %input% == "--help" GOTO :help_message
GOTO :varin
:varin
@@ -148,19 +56,22 @@ IF NOT "%~1" =="" (
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" =="-k" SET "errorswitch=0"
IF "%~1" =="-p" SET "picswitch=0"
IF "%~1" =="-v" SET "loglevel=%~2" & SHIFT
IF "%~1" =="-k" SET "errorswitch=1"
IF "%~1" =="-p" SET "picswitch=1"
SHIFT & GOTO :varin
)
GOTO :help_check_2
:help_check_2
:: Noob proofing the script to prevent it from breaking should critical settings not be defined
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=0
IF NOT DEFINED filetype SET "filetype=gif"
IF NOT DEFINED loglevel SET "loglevel=error"
GOTO :safchek
:safchek
@@ -169,7 +80,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 Not a valid file type
GOTO :EOF
)
IF "%filetype%"=="png" SET filetype=apng
@@ -243,15 +154,25 @@ IF NOT DEFINED start_time (
GOTO :script_start
:script_start
:: Storing FFmpeg version string
FOR /F "delims=" %%a in ('ffmpeg -version') DO (
IF NOT DEFINED version (
SET "version=%%a"
) ELSE IF NOT DEFINED build (
SET "build=%%a"
)
)
:: Displaying FFmpeg version string and creating the working directory
ECHO %version%
ECHO %build%
ECHO Output file: %output%
ECHO Creating Working Directory...
ECHO Output file: %output%
ECHO Creating working directory...
MD "%WD%"
:palettegen
:: Putting together command to generate palette
SET palette=%WD%\palette
SET frames=%palette%_%%05d
SET filters=fps=%fps%,scale=%scale%:-1:flags=lanczos
@@ -267,8 +188,8 @@ IF DEFINED colormax (
)
:: Executing command to generate palette
ECHO Generating Palette...
ffmpeg -v warning %trim% -i %vid% -vf "%filters%,%encode%%mcol%" -y "%frames%.png"
ECHO Generating palette...
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" (
@@ -320,7 +241,7 @@ IF DEFINED bayerscale SET bayer=:bayer_scale=%bayerscale%
:: Executing the encoding command
ECHO Encoding animation...
ffmpeg -v warning %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%" (
@@ -333,7 +254,98 @@ IF DEFINED picswitch START "" "%output%"
:cleanup
:: Cleaning up
ECHO Deleting Temporary files...
ECHO Deleting temporary files...
RMDIR /S /Q "%WD%"
ENDLOCAL
ECHO Done!
GOTO :EOF
:help_message
:: Print usage message
ECHO:
ECHO Video to GIF/APNG/WEBP converter v5.5
ECHO ^(C^) 2017-2022, MDHEXT ^&^ Nabi KaramAliZadeh ^<nabikaz@gmail.com^>
ECHO:
ECHO You can download this fork from here:
ECHO https://github.com/MDHEXT/video2gif
ECHO You can download the original release here:
ECHO https://github.com/NabiKAZ/video2gif
ECHO This tool uses ffmpeg, you can download that here:
ECHO https://www.ffmpeg.org/download.html#build-windows
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:
ECHO Usage:
ECHO vid2ani [input_file] [Arguments]
ECHO:
ECHO Arguments:
ECHO:
ECHO -t Output file type.
ECHO Valid: 'gif' (default), 'png', 'webp'.
ECHO:
ECHO -o Output file.
ECHO The default is the same name as the input video.
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:
ECHO -s Start time of the animation (HH:MM:SS.MS)
ECHO:
ECHO -e End time of the animation (HH:MM:SS.MS)
ECHO:
ECHO -f Framerate in frames per second.
ECHO The default is 15.
ECHO:
ECHO -d Dithering algorithm to be used.
ECHO The default is 0 (None).
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:
ECHO -m Palettegen mode - one of 3 modes listed below.
ECHO The default is 1 (diff).
ECHO:
ECHO -c The maximum amount of colors useable per palette.
ECHO Range 3 - 256 (default)
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:
ECHO -v Set FFmpeg log level, for troubleshooting.
ECHO The default log level is 'error'
ECHO:
ECHO -p Opens the resulting animation in your default Photo Viewer.
ECHO:
ECHO Dithering Modes:
ECHO 0: None
ECHO 1: Bayer
ECHO 2: Heckbert
ECHO 3: Floyd Steinberg
ECHO 4: Sierra2
ECHO 5: Sierra2_4a
ECHO 6: sierra3
ECHO 7: burkes
ECHO 8: atkinson
ECHO:
ECHO Palettegen Modes:
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 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 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
ECHO assistance^^!
GOTO :EOF