Skip to content

Instantly share code, notes, and snippets.

@sooop
Last active August 18, 2022 15:05
Show Gist options
  • Save sooop/3c8c08afbd29336f8fb74dd329e2317f to your computer and use it in GitHub Desktop.
Save sooop/3c8c08afbd29336f8fb74dd329e2317f to your computer and use it in GitHub Desktop.
convert video file to animated gif with ffmpeg
@echo off
@setlocal
set infile=%1
set outfile=%2
shift & shift
set fps=10
set w=320
:loop
IF NOT "%1"=="" (
IF "%1"=="-fps" (
set fps=%2
shift
)
IF "%1"=="-w" (
set w=%2
shift
)
shift
GOTO :loop
)
:main
@set start_time="0:0"
@set filter1="[0:v]fps=%fps%,scale=%w%:-1:flags=lanczos,split=2[x][y]"
@set filter2="[y]palettegen[p]"
@set filter3="[x][p]paletteuse[z]"
@ffmpeg -v warning -ss %start_time% -i %infile% ^
-lavfi "%filter1%;%filter2%;%filter3%" -map "[z]" ^
-y %outfile%
@endlocal
@echo on
def main [ src: path
out: path = "out.gif"
--width(-w): int = 320
--fps: int = 10
] {
let filters = ([
$"[0:v]fps=($fps),scale=($width):-1:flags=lanczos,split=2[x][y]"
"[y]palettegen[p]"
"[x][p]paletteuse[z]" ] | str collect ";")
[-v warning -ss "0:0" -i $src -lavfi $filters -map "[z]" -y $out] | ^ffmpeg $in
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment