Created
January 29, 2018 19:49
-
-
Save kg/7e64345b8ee258181be5bfb0e8f5f5c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@if [%6]==[] goto error | |
@goto ok | |
:error | |
@echo USAGE: video2gif START_TIME DURATION WIDTH FRAME_RATE (DITHER_OPTIONS) (CROP_RECTANGLE width:height:x:y) (EQ_OPTIONS) INPUT OUTPUT | |
@goto end | |
:ok | |
@set PALETTE="%TEMP%\palette.png" | |
@set START_TIME=%1 | |
@set DURATION=%2 | |
@set WIDTH=%3 | |
@set FRAME_RATE=%4 | |
@if [%7]==[] goto dither_omitted | |
@if [%8]==[] goto crop_omitted | |
@if [%9]==[] goto eq_omitted | |
:all_specified | |
@set DITHER_OPTIONS=%5 | |
@set CROP_RECTANGLE=crop=%6, | |
@set EQ_OPTIONS=,eq=%7 | |
@set INPUT=%8 | |
@set OUTPUT=%9 | |
@goto who_cares | |
:eq_omitted | |
@set DITHER_OPTIONS=%5 | |
@set CROP_RECTANGLE=crop=%6, | |
@set EQ_OPTIONS= | |
@set INPUT=%7 | |
@set OUTPUT=%8 | |
@goto who_cares | |
:crop_omitted | |
@set DITHER_OPTIONS=%5 | |
@set CROP_RECTANGLE= | |
@set EQ_OPTIONS= | |
@set INPUT=%6 | |
@set OUTPUT=%7 | |
@goto who_cares | |
:dither_omitted | |
@set DITHER_OPTIONS=dither=bayer:bayer_scale=4 | |
@set CROP_RECTANGLE= | |
@set EQ_OPTIONS= | |
@set INPUT=%5 | |
@set OUTPUT=%6 | |
@goto who_cares | |
:who_cares | |
@set PALETTEUSE=%DITHER_OPTIONS%:diff_mode=rectangle | |
@set FILTERS=fps=%FRAME_RATE%,%CROP_RECTANGLE%scale=%WIDTH%:-1:flags=lanczos%EQ_OPTIONS% | |
@set OPTS_PREFIX=-v warning -ss %START_TIME% -t %DURATION% -i %INPUT% | |
ffmpeg %OPTS_PREFIX% -vf "%FILTERS%,palettegen=stats_mode=diff:max_colors=256" -y %PALETTE% | |
ffmpeg %OPTS_PREFIX% -i %PALETTE% -lavfi "%FILTERS% [x]; [x][1:v] paletteuse=%PALETTEUSE%" -y %OUTPUT% | |
:end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment