Skip to content

Instantly share code, notes, and snippets.

@pezcode
Last active May 16, 2020 00:56
Show Gist options
  • Save pezcode/a77f94766c4e3f696be7357af4572716 to your computer and use it in GitHub Desktop.
Save pezcode/a77f94766c4e3f696be7357af4572716 to your computer and use it in GitHub Desktop.
FFmpeg: convert video to animated .gif (PowerShell script)
# convert video to animated .gif
# requires FFmpeg 2.6 or higher
# http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
param(
[Parameter(Mandatory=$true)][string]$InputPath,
[string]$OutputPath,
[int]$Height=0 # 0 for input height
)
if(-not $OutputPath) {
$OutputPath = [System.IO.Path]::ChangeExtension($InputPath, "gif")
}
$filters = "scale=-1:${Height}:flags=lanczos"
$palette = "palette.png"
ffmpeg -y -v warning -i $InputPath -vf "$filters, palettegen" $palette
ffmpeg -y -v warning -i $InputPath -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" $OutputPath
Remove-Item $palette
@Delivator
Copy link

Works perfectly, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment