Skip to content

Instantly share code, notes, and snippets.

@cumulus13
Last active December 22, 2025 09:17
Show Gist options
  • Select an option

  • Save cumulus13/86b8138ca9567fb2f8d5fb774939d594 to your computer and use it in GitHub Desktop.

Select an option

Save cumulus13/86b8138ca9567fb2f8d5fb774939d594 to your computer and use it in GitHub Desktop.
MP4 to GIF with FFMPEG
:: File: mp4togif.bat
:: Author: Hadi Cahyadi <cumulus13@gmail.com>
:: Date: 2025-12-22
:: Description:
:: License: MIT
@echo off
setlocal
:: --- Mandatory Input Checking ---
if "%~1" == "" (
echo.
echo ❌ ERROR: You must provide an input file.
echo.
goto :eof
)
:: --- Input Variable Settings ---
set "INPUT_FILE=%~1"
:: Output default: Input Name without extention (e.g., color-notify)
set "OUTPUT_NAME=%~n1"
:: --- Simplified Output Logic ---
:: IF argument %2 EXISTS (NOT EMPTY), OVERRIDE OUTPUT_NAME
if not "%~2" == "" set "OUTPUT_NAME=%~n2"
:: Add .gif extension to output name (always)
set "OUTPUT_FILE=%OUTPUT_NAME%.gif"
:: --- GIF Parameter Settings ---
set "START_TIME=5"
set "DURATION=15"
set "FPS=12"
set "WIDTH=1280"
:: --- FFmpeg command ---
echo.
echo 🎬 Processing Input: "%INPUT_FILE%"
echo πŸ–ΌοΈ The output will be saved as: "%OUTPUT_FILE%"
echo πŸ•’ Duration: %DURATION% seconds (Starting from %START_TIME% second)
echo βš™οΈ Generate GIFs...
echo.
ffmpeg ^
-ss %START_TIME% ^
-t %DURATION% ^
-i "%INPUT_FILE%" ^
-vf "fps=%FPS%,scale=%WIDTH%:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" ^
-loop 0 ^
"%OUTPUT_FILE%"
:: --- Checking Results ---
if exist "%OUTPUT_FILE%" (
echo.
echo βœ… Done! The GIF file has been created.
) else (
echo.
echo ❌ ERROR: FFmpeg failed to create GIF file.
echo.
)
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment