Created
July 2, 2024 01:11
-
-
Save dowoge/238152d26ded704a14bc60627128a024 to your computer and use it in GitHub Desktop.
sprite sheet generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
if "%1"=="" ( | |
echo Please provide the input file as the first argument. | |
goto :eof | |
) | |
if "%2"=="" ( | |
echo Please provide the scale as the third argument. | |
goto :eof | |
) | |
if "%3"=="" ( | |
echo Please provide the output file name as the fourth argument. | |
goto :eof | |
) | |
set input_file=%1 | |
set scale_width=%2 | |
set output_file=%3 | |
set video_string="scale=%scale_width%:-1" | |
if not "%4"=="" ( | |
set video_string=%video_string%,colorkey=%4:0.1:0.1 | |
) | |
set temp_folder=%temp%\sprite_sheet_frames | |
mkdir %temp_folder% | |
ffprobe -loglevel error -stats -select_streams -count_frames -show_entries stream=nb_read_frames -print_format default=nokey=1:noprint_wrappers=1 %input_file% > %temp_folder%/frame_count.txt | |
set /p frame_count=<%temp_folder%/frame_count.txt | |
set /a row=1 | |
set /a col=%frame_count%/%row% | |
:loop | |
set /a col=%frame_count%/%row% | |
if %row% gtr %col% ( | |
goto found | |
) | |
set /a row=%row%+1 | |
goto loop | |
:found | |
set /a col=%col%+1 | |
ffmpeg -i %input_file% -nostats -loglevel 0 -vf "%video_string%,split[a][b];[a]alphaextract[am];[b][am]alphamerge" "%temp_folder%/frame_%%04d.bmp" | |
ffmpeg -i "%temp_folder%/frame_%%04d.bmp" -nostats -loglevel 0 -filter_complex tile=%row%x%col% -update true %output_file% | |
rmdir %temp_folder% /Q/S | |
echo Done, the sprite sheet is saved as %output_file%. There are %frame_count% frames on a grid of size %row%x%col% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment