param( [ValidateRange(1, 32)] [int]$Jobs = 4 ) $ErrorActionPreference = "Stop" . (Join-Path $PSScriptRoot "native_dep_versions.ps1") foreach ($required in @($Bash, $Make, (Join-Path $MingwBin "gcc.exe"), $FfmpegSource)) { if (-not (Test-Path -LiteralPath $required)) { throw "Required path not found: $required" } } $BuildToolsBin = Join-Path $ToolsRoot "build-bin" New-Item -ItemType Directory -Force $FfmpegBuild, $FfmpegInstall, $BuildToolsBin | Out-Null Copy-Item -LiteralPath $Make -Destination (Join-Path $BuildToolsBin "make.exe") -Force function Convert-ToBashPath([string]$Path) { if ($Path.Contains("'")) { throw "Paths containing a single quote are not supported: $Path" } $result = & $Bash -lc "cygpath -u '$Path'" if ($LASTEXITCODE -ne 0) { throw "Cannot convert path for Git Bash: $Path" } return $result.Trim() } $SourcePosix = Convert-ToBashPath $FfmpegSource $BuildPosix = Convert-ToBashPath $FfmpegBuild $InstallPosix = Convert-ToBashPath $FfmpegInstall $SourceMake = $FfmpegSource.Replace("\", "/") $MingwBinPosix = Convert-ToBashPath $MingwBin $BuildToolsPosix = Convert-ToBashPath $BuildToolsBin $NasmRootPosix = Convert-ToBashPath $NasmRoot $BuildCommand = @" set -e export PATH='${NasmRootPosix}:${BuildToolsPosix}:${MingwBinPosix}:/usr/bin:/bin' cd '$BuildPosix' if [ ! -f ffbuild/config.mak ]; then '$SourcePosix/configure' \ --prefix='$InstallPosix' \ --target-os=mingw32 \ --arch=x86_64 \ --cc=gcc \ --cxx=g++ \ --ar=ar \ --ranlib=ranlib \ --strip=strip \ --windres=windres \ --enable-shared \ --disable-static \ --disable-debug \ --disable-doc \ --disable-programs \ --disable-avdevice \ --disable-avformat \ --disable-avfilter \ --disable-swresample \ --disable-postproc \ --disable-network \ --disable-everything \ --enable-avcodec \ --enable-avutil \ --enable-swscale \ --enable-decoder=h264 \ --enable-decoder=hevc \ --enable-decoder=mjpeg \ --enable-parser=h264 \ --enable-parser=hevc \ --enable-parser=mjpeg \ --enable-hwaccel=h264_d3d11va \ --enable-hwaccel=hevc_d3d11va \ --enable-hwaccel=h264_d3d11va2 \ --enable-hwaccel=hevc_d3d11va2 \ --enable-hwaccel=h264_dxva2 \ --enable-hwaccel=hevc_dxva2 \ --extra-cflags=-O2 fi # Native mingw32-make cannot resolve Git Bash paths such as /c/source. sed -i 's|${SourcePosix}|${SourceMake}|g' Makefile ffbuild/config.mak make -j$Jobs "@ & $Bash -lc $BuildCommand if ($LASTEXITCODE -ne 0) { throw "FFmpeg build failed" } $binDir = Join-Path $FfmpegInstall "bin" $libDir = Join-Path $FfmpegInstall "lib" $pkgConfigDir = Join-Path $libDir "pkgconfig" $includeDir = Join-Path $FfmpegInstall "include" New-Item -ItemType Directory -Force $binDir, $libDir, $pkgConfigDir, $includeDir | Out-Null foreach ($component in @("avcodec", "avutil", "swscale")) { $buildComponent = Join-Path $FfmpegBuild "lib$component" $sourceComponent = Join-Path $FfmpegSource "lib$component" $includeComponent = Join-Path $includeDir "lib$component" New-Item -ItemType Directory -Force $includeComponent | Out-Null $dll = Get-ChildItem -LiteralPath $buildComponent -Filter "$component-*.dll" | Select-Object -First 1 $importLibrary = Join-Path $buildComponent "$component.lib" $pkgConfig = Join-Path $buildComponent "lib$component.pc" foreach ($required in @($dll.FullName, $importLibrary, $pkgConfig)) { if (-not $required -or -not (Test-Path -LiteralPath $required)) { throw "FFmpeg artifact not found: $required" } } Copy-Item -LiteralPath $dll.FullName -Destination $binDir -Force Copy-Item -LiteralPath $importLibrary -Destination (Join-Path $libDir "$component.lib") -Force Copy-Item -LiteralPath $importLibrary -Destination (Join-Path $libDir "lib$component.dll.a") -Force Copy-Item -LiteralPath $pkgConfig -Destination $pkgConfigDir -Force Get-ChildItem -LiteralPath $sourceComponent -File -Filter "*.h" | Copy-Item -Destination $includeComponent -Force Get-ChildItem -LiteralPath $buildComponent -File -Filter "*.h" | Copy-Item -Destination $includeComponent -Force } $Avcodec = Get-ChildItem -LiteralPath $binDir -Filter "avcodec-*.dll" | Select-Object -First 1 if (-not $Avcodec) { throw "FFmpeg staging finished but avcodec DLL is missing" } Write-Host "FFmpeg installed to $FfmpegInstall"