Convert all GIF/MP4/WEBM to APNG using FFMPEG

If you want to make your old GIF/WEBM/MP4 play automatically in 8chan

Last Update: 2025-05-21 Added palettegen command which should reduce the APNG file size considerably (as long as it's not too long)

Instruction

Make a new text file, paste the code below, and save it with a ".bat" extension (i.e convert.bat)

Or you can just download the file here:
v0.1 - https://files.catbox.moe/fojfvr.bat
v0.2 - https://files.catbox.moe/5xxjfv.bat
v0.3 - https://files.catbox.moe/glwrj2.bat

Make sure you have FFMPEG installed: https://www.ffmpeg.org/download.html

Code to paste (v0.3)

@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
Edit

Pub: 27 Apr 2025 01:58 UTC

Edit: 21 May 2025 00:51 UTC

Views: 515