ffmpeg - documentation
ffmpeg - downloads
High Quality GIF with ffmpeg
- Download ffmpeg and unzip wherever you want it to reside.
- From an admin command prompt, open the environment variables editor:
rundll32 sysdm.cpl,EditEnvironmentVariables
- Select
Path
from the System Variables section at the bottom, then click Edit below - Add the path to the
\bin
folder in the extracted directory - Be sure to click Ok to close out of the
Path
editor and the Environment Variable editor
I've converted the bash script outlined in High Quality GIF with ffmpeg into a simple parameterized PowerShell script.
Create-Gif.ps1
[CmdletBinding()]
Param(
[Parameter()]
[string]$origin,
[Parameter()]
[string]$destination,
[Parameter()]
[string]$options = $null,
[Parameter()]
[string]$log = $null
)
$palette = "${env:TEMP}\palette.png"
$filters = if ($options.Length -gt 0) { $options } else { "scale=512:-1:flags=bicubic" }
$logLevel = if ($log.Length -gt 0) { $log } else { "panic" }
ffmpeg -v $logLevel -i $origin -vf "$filters,palettegen" -y $palette
ffmpeg -v $logLevel -i $origin -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $destination
Syntax
{directory-where-script-is-saved}>.\Create-Gif.ps1 {origin-video} {destination-gif} -log {optional logging level} -options {optional filter options}
Examples
# Basic Usage
D:\Desktop>.\Create-Gif.ps1 D:\Captures\demo.mp4 D:\Captures\demo.gif
# With Options
D:\Desktop>.\Create-Gif.ps1 D:\Captures\demo.mp4 D:\Captures\demo.gif -options "trim=start=5:end=10,scale=320:-1:flags=lanczos"
# With Log
D:\Desktop>.\Create-Gif.ps1 D:\Captures\demo.mp4 D:\Captures\demo.gif -log debug
The options relate to the options set for the palettegen filter. The default is scale=720:-1:flags=lanczos
, which specifies an aspect ratio-locked width of 720px and uses the lanczos
scaling algorithm.
In the example above, the options limit the gif to 15 frames per second and an aspect ratio-locked width of 320px.
For detailed information on filters, see the following resources:
ffmpeg - Filters Table of Contents
ffmpeg - Video Filters
ffmpeg - FPS
ffmpeg - Scale
ffmpeg - Scale Algorithm Flags
Source video that will be used to make .gif files: