Last active
May 16, 2020 00:56
-
-
Save pezcode/a77f94766c4e3f696be7357af4572716 to your computer and use it in GitHub Desktop.
FFmpeg: convert video to animated .gif (PowerShell script)
This file contains 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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works perfectly, thanks!