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"
@Docteur-RS
Copy link

+1

@max-novak
Copy link

Similar to Maxhem2 but I made a version for scripting. You can also use winget to download the package with aliases installed here if you don't want to install manually.

  • This solution doesn't require admin rights to run (safer)
  • Set-Alias also only persists for the runtime of the script
  • Note: I am not sure how to conditionally check Get-Command using parameter syntax (e.g. Get-Command ffmpeg, ffplay, ffprobe), it doesn't seem to fulfill the conditional correctly. Let me know if someone finds a solution for this.
if (Get-Command ffmpeg -ErrorAction SilentlyContinue) {
    Write-Host "ffmpeg is already installed."
} else {
    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 "$env:APPDATA" -Force #Force overwrites pre-existing files
    Set-Alias ffmpeg "$env:APPDATA\ffmpeg-release-essentials\bin\ffmpeg.exe"
    Set-Alias ffplay "$env:APPDATA\ffmpeg-release-essentials\bin\ffplay.exe"
    Set-Alias ffprobe "$env:APPDATA\ffmpeg-release-essentials\bin\ffprobe.exe"
    Remove-Item ffmpeg.zip #cleanup
    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