Skip to content

Instantly share code, notes, and snippets.

@Lovesan
Last active January 12, 2022 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lovesan/5d75eef4e312f4f95e4502d901b8fad9 to your computer and use it in GitHub Desktop.
Save Lovesan/5d75eef4e312f4f95e4502d901b8fad9 to your computer and use it in GitHub Desktop.
using namespace System.IO;
$ErrorActionPreference = 'Stop'
function VideoToGif{
Param(
[Parameter(Mandatory=$true)][string] $InFile,
[Parameter(Mandatory=$true)][string] $OutFile,
[int]$Width=320,
[int]$Height=-1,
[double]$Start=0.0,
[double]$Length=0)
$paletteFileName = [Path]::Combine([Path]::GetTempPath(), [Path]::GetRandomFileName()) + ".png";
ffmpeg -y -ss $Start -t $Length -i "$InFile" -filter_complex "[0:v]scale=${Width}:${Height}[v];[v]palettegen" "$paletteFileName"
if(!$?) { return $null }
ffmpeg -y -ss $Start -t $Length -i "$InFile" -i "$paletteFileName" -filter_complex "[0:v]scale=${Width}:${Height}[v];[v][1:v]paletteuse" "$OutFile"
$rv = $?
[File]::Delete($paletteFileName)
if ($rv) { return $OutFile } else { return $null }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment