58 lines
1.6 KiB
Batchfile
58 lines
1.6 KiB
Batchfile
|
@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
|
||
|
if "%scale_width%"=="0" (
|
||
|
set scale_width=-1
|
||
|
)
|
||
|
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%
|
||
|
|
||
|
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "%temp_folder%/frame_0001.bmp" > %temp_folder%/frame_size.txt
|
||
|
set /p frame_size=<%temp_folder%/frame_size.txt
|
||
|
|
||
|
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% with a frame size of %frame_size%
|