@echo off
setlocal enabledelayedexpansion
:: Save the current directory
set "currentDir=%~dp0"
set /a count=0
echo GIF/MP4/WEBM to APNG Conversion v0.3
echo A simple script that will automatically convert all GIF/MP4/WEBM to APNG using FFMPEG in the CURRENT FOLDER
echo Current Folder: %currentDir%
echo(
echo Please select which filetype you want to convert to APNG
echo 1) GIF
echo 2) MP4
echo 3) WEBM
echo 4) All of the above
echo(
CHOICE /M Select /C 1234
If Errorlevel 4 Goto 4
If Errorlevel 3 Goto 3
If Errorlevel 2 Goto 2
If Errorlevel 1 Goto 1
:1
cls
call :convertGIF
Goto end
:2
cls
call :convertMP4
Goto end
:3
cls
call :convertWEBM
Goto end
:4
cls
call :convertGIF
call :convertMP4
call :convertWEBM
Goto end
:: Convert all .gif files into .apng
:convertGIF
echo(
echo Converting GIF to APNG...
echo(
for %%f in ("%currentDir%*.gif") do (
echo Converting %%~nxf ...
ffmpeg -hide_banner -loglevel error -i "%%~nxf" -vf "scale='if(gt(iw,ih),200,-1)':'if(gt(iw,ih),-1,200)':flags=lanczos,split [a][b];[a] palettegen=stats_mode=diff [p];[b][p] paletteuse=dither=none" -f apng -plays 0 "%%~nf.apng"
set /a count+=1
)
EXIT /B
:: Convert all .mp4 files into .apng
:convertMP4
echo(
echo Converting MP4 to APNG...
echo(
for %%f in ("%currentDir%*.mp4") do (
echo Converting %%~nxf ...
ffmpeg -hide_banner -loglevel error -i "%%~nxf" -vf "fps=10, scale='if(gt(iw,ih),200,-1)':'if(gt(iw,ih),-1,200)':flags=lanczos,split [a][b];[a] palettegen=stats_mode=diff [p];[b][p] paletteuse=dither=none" -f apng -plays 0 "%%~nf.apng"
set /a count+=1
)
EXIT /B
:: Convert all .webm files into .apng
:convertWEBM
echo(
echo Converting WEBM to APNG...
echo(
for %%f in ("%currentDir%*.webm") do (
echo Converting %%~nxf ...
ffmpeg -hide_banner -loglevel error -i "%%~nxf" -vf "fps=8, scale='if(gt(iw,ih),200,-1)':'if(gt(iw,ih),-1,200)':flags=lanczos,split [a][b];[a] palettegen=stats_mode=diff [p];[b][p] paletteuse=dither=none" -f apng -plays 0 "%%~nf.apng"
set /a count+=1
)
EXIT /B
:end
:: Rename all APNG to PNG so Explorer can preview it
for %%f in ("%currentDir%*.apng") do (
if not exist "%%~nf.png" (
ren "%%~nxf" "%%~nf.png"
) else (
echo(
echo Similar filename detected, skipping renaming "%%~nxf"
del "%%~nxf"
)
)
echo(
echo Conversion completed, %count% file converted
pause
start "" "%currentDir%"
exit