Skip to content

Instantly share code, notes, and snippets.

@ndorigatti
Last active August 29, 2015 14:27
Show Gist options
  • Save ndorigatti/ac1a725b61d1798cced9 to your computer and use it in GitHub Desktop.
Save ndorigatti/ac1a725b61d1798cced9 to your computer and use it in GitHub Desktop.
Giffify - easily create optimised GIFs from a video (On Windows). This assumes you have ffmpeg.exe in the same folder or in the System PATH.
@echo off
REM !/bin/sh
REM License for any modification to the original (linked below):
REM ----------------------------------------------------------------------------
REM "THE BEER-WARE LICENSE" (Revision 42):
REM Sebastiano Poggi wrote this file. As long as you retain this notice you
REM can do whatever you want with this stuff. If we meet some day, and you think
REM this stuff is worth it, you can buy me a beer in return.
REM ----------------------------------------------------------------------------
REM
REM Based upon http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
REM Usage: giffify.sh inputFile outputFile [targetHeight] [targetFps]
REM Defaults: defaultHeight = 500px, targetFps = 15
REM ----------------------------------------------------------------------------
REM The 'bat' porting was done by Nicola Dorigatti, basing on original shell script:
REM https://gist.github.com/rock3r/a923a79e8d8a850911aa
REM Usage: giffify.bat inputFile outputFile [targetHeight] [targetFps]
REM Defaults: defaultHeight = 500px, targetFps = 15
set inputFile="%1"
set outputFile="%2"
set desiredHeight=%3
IF !%desiredHeight%==! set desiredHeight=500
set fps=%4
IF !%fps%==! set fps=15
set palette=palette.png
set filters=fps=%fps%,scale=-1:%desiredHeight%:flags=lanczos
@echo on
ffmpeg.exe -v warning -i "%inputFile%" -vf "%filters%,palettegen" -y %palette%
IF EXIST %palette% (
ffmpeg.exe -v warning -i %inputFile% -i %palette% -lavfi "%filters% [x]; [x][1:v] paletteuse" -y %outputFile%
DEL "%palette%"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment