Skip to content

Instantly share code, notes, and snippets.

@0b5vr
Last active December 6, 2023 04:16
Show Gist options
  • Save 0b5vr/12f28deeb63fdb593c776d7ca863a17a to your computer and use it in GitHub Desktop.
Save 0b5vr/12f28deeb63fdb593c776d7ca863a17a to your computer and use it in GitHub Desktop.
Batch: any video to gif
@echo off
setlocal
rem (c) 0b5vr, MIT License https://opensource.org/licenses/MIT
set FILE=""
set START=0
set TIME=65536
set WIDTH=-1
set COLORS=32
set RATE=50
set OUTPUT=""
:params
if [%1] == [] goto process
if "%1" == "-h" goto help
if "%1" == "-i" set FILE=%2
if "%1" == "-s" set START=%2
if "%1" == "-t" set TIME=%2
if "%1" == "-w" set WIDTH=%2
if "%1" == "-c" set COLORS=%2
if "%1" == "-r" set RATE=%2
if "%1" == "-o" set OUTPUT=%2
shift
shift
goto params
:process
if %FILE% == "" goto help
if %OUTPUT% == "" set OUTPUT=%FILE%.gif
set PALETTE=palette.png
set FILTERS=fps=%RATE%,scale=%WIDTH%:-1:flags=lanczos
ffmpeg -ss %START% -t %TIME% -v warning -i %FILE% -vf "%FILTERS%,palettegen=max_colors=%COLORS%" -y %PALETTE%
ffmpeg -ss %START% -t %TIME% -v warning -i %FILE% -i %PALETTE% -lavfi "%FILTERS% [x]; [x][1:v] paletteuse" -r %RATE% %OUTPUT%
del %PALETTE%
goto end
:help
echo Usage:
echo vidya2gif -i input.mp4
echo.
echo Options:
echo -h show this help
echo -i input file
echo -s start time in seconds
echo -t duration in seconds
echo -w width in pixels
echo -c number of colors
echo -r frame rate
echo -o output file
echo.
goto end
:end
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment