Skip to content

Instantly share code, notes, and snippets.

@AnjanaMadu
Created April 10, 2023 15:08
Show Gist options
  • Save AnjanaMadu/5f9689e9572492a50089f4a74b9b8de5 to your computer and use it in GitHub Desktop.
Save AnjanaMadu/5f9689e9572492a50089f4a74b9b8de5 to your computer and use it in GitHub Desktop.
A powershell script to install ffmpeg in windows easily
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
if (!$isAdmin) {
Write-Host "Please run this script as administrator."
exit
}
if (Get-Command ffmpeg -ErrorAction SilentlyContinue) {
Write-Host "ffmpeg is already installed."
exit
}
if (!(Get-Command 7z -ErrorAction SilentlyContinue)) {
Write-Host "7zip is not installed. Please install it first."
}
Write-Host "Downloading ffmpeg..."
Invoke-WebRequest -Uri "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.7z" -OutFile "ffmpeg.7z"
Write-Host "Extracting..."
7z x -y -o"C:\" "ffmpeg.7z"
$ffmpegFolder = Get-ChildItem -Path "C:\" -Filter "ffmpeg-*" -Directory
Rename-Item -Path $ffmpegFolder -NewName "ffmpeg"
Write-Host "Adding ffmpeg to PATH..."
$envPath = [Environment]::GetEnvironmentVariable("PATH", "Machine")
[Environment]::SetEnvironmentVariable("PATH", $envPath + ";C:\ffmpeg\bin", "Machine")
Write-Host "ffmpeg is installed. Following commands are available: ffmpeg, ffplay, ffprobe"
@Maxhem2
Copy link

Maxhem2 commented Oct 29, 2024

$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
if (!$isAdmin) {
    Write-Host "Please run this script as administrator."
    exit
}

if (Get-Command ffmpeg -ErrorAction SilentlyContinue) {
    Write-Host "ffmpeg is already installed."
    exit
}

Write-Host "Downloading ffmpeg..."
Invoke-WebRequest -Uri "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip" -OutFile "ffmpeg.zip"

Write-Host "Extracting..."
# Use the native Windows zip command
Expand-Archive -Path "ffmpeg.zip" -DestinationPath "C:\"

$ffmpegFolder = Get-ChildItem -Path "C:\" -Filter "ffmpeg-*" -Directory
Rename-Item -Path $ffmpegFolder.FullName -NewName "ffmpeg"

Write-Host "Adding ffmpeg to PATH..."
$envPath = [Environment]::GetEnvironmentVariable("PATH", "Machine")
[Environment]::SetEnvironmentVariable("PATH", $envPath + ";C:\ffmpeg\bin", "Machine")

Write-Host "ffmpeg is installed. Following commands are available: ffmpeg, ffplay, ffprobe"

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