1+ param (
2+ [Parameter (Mandatory = $false )]
3+ [string ]$Platform ,
4+
5+ [Parameter (Mandatory = $false )]
6+ [string ]$OutputPath
7+ )
8+
9+ $ErrorActionPreference = " Stop"
10+
11+ # If the platform is not specified, use the current OS/arch
12+ if (-not $Platform ) {
13+ $arch = [Runtime.InteropServices.RuntimeInformation ]::OSArchitecture
14+
15+ if ($isWindows ) {
16+ $Platform = " windows-$arch "
17+ } elseif ($isLinux ) {
18+ $Platform = " linux-$arch "
19+ } elseif ($isMacOS ) {
20+ $Platform = " osx-$arch "
21+ } else {
22+ throw " Unsupported platform"
23+ }
24+ }
25+
26+ # Normalize platform identifier
27+ $Platform = $Platform.ToLower ().Replace(" win-" , " windows-" )
28+ $fileName = if ($Platform.Contains (" windows-" )) { " ffmpeg.exe" } else { " ffmpeg" }
29+
30+ # If the output path is not specified, use the current directory
31+ if (-not $OutputPath ) {
32+ $OutputPath = " $PSScriptRoot /$fileName "
33+ }
34+
35+ # If the output path is an existing directory, append the default file name for the platform
36+ if (Test-Path $OutputPath - PathType Container) {
37+ $OutputPath = Join-Path $OutputPath $fileName
38+ }
39+
40+ # Delete the existing file if it exists
41+ if (Test-Path $OutputPath ) {
42+ Remove-Item $OutputPath
43+ }
44+
45+ # Download the archive
46+ Write-Host " Downloading FFmpeg for $Platform ..."
47+ $http = New-Object System.Net.WebClient
48+ try {
49+ $http.DownloadFile (" https://github.com/Tyrrrz/FFmpegBin/releases/download/7.0/ffmpeg-$Platform .zip" , " $OutputPath .zip" )
50+ } finally {
51+ $http.Dispose ()
52+ }
53+
54+ try {
55+ # Extract FFmpeg
56+ Add-Type - Assembly System.IO.Compression.FileSystem
57+ $zip = [IO.Compression.ZipFile ]::OpenRead(" $OutputPath .zip" )
58+ try {
59+ [IO.Compression.ZipFileExtensions ]::ExtractToFile($zip.GetEntry ($fileName ), $OutputPath )
60+ } finally {
61+ $zip.Dispose ()
62+ }
63+
64+ Write-Host " Done downloading FFmpeg."
65+ } finally {
66+ # Clean up
67+ Remove-Item " $OutputPath .zip" - Force
68+ }
0 commit comments