<# .SYNOPSIS Builds the video repair engine (untrunc compiled to WebAssembly, as packaged by FootageRescue's engine) and copies it to frontend/vendor/local/untrunc@1/, where the site serves it from /vendor/. The engine is GPL-2.0-or-later. The page talks to it only through its Web Worker's messages. Everything it is built from is published at /source/untrunc/: the engine repository at the pinned commit (source/engine/) and the FFmpeg release it compiles in (source/ffmpeg-3.3.9.tar.xz). Nothing is installed on this machine; Docker Desktop and git must be available. #> $ErrorActionPreference = 'Continue' Set-Location $PSScriptRoot $Repo = 'https://github.com/aletripodi/footagerescue-engine' $Commit = '179bf09cc8db7ec9a29de14ffa7a9ddf3a2924e3' $FfmpegUrl = 'https://www.ffmpeg.org/releases/ffmpeg-3.3.9.tar.xz' $FfmpegSha = 'ae34f14fffa65a1a59b256737ca9af7bf4e296b7c4320d42512350126ce06c84' $work = Join-Path $PSScriptRoot 'dist' if (Test-Path $work) { Remove-Item -Recurse -Force $work } New-Item -ItemType Directory -Force $work | Out-Null $src = Join-Path $work 'engine' & git -c core.autocrlf=false clone -q $Repo $src & git -C $src checkout -q $Commit $head = (& git -C $src rev-parse HEAD).Trim() if ($head -ne $Commit) { throw "engine checkout is $head, expected $Commit" } $out = Join-Path $work 'out' & docker build --build-arg "ENGINE_COMMIT=$Commit" --output "type=local,dest=$out" $src if ($LASTEXITCODE -ne 0) { throw 'docker build failed' } $dest = Join-Path $PSScriptRoot '..\..\vendor\local\untrunc@1' New-Item -ItemType Directory -Force $dest | Out-Null foreach ($f in 'untrunc.mjs', 'untrunc.wasm', 'LICENSE.txt', 'SOURCE.txt') { Copy-Item (Join-Path $out $f) $dest -Force } # johnmcm.com's one change to the engine (GPL-2.0 section 2(a) notice below): # two more methods in the worker, so the page can pass untrunc's own "-sv" # option, which stretches the picture to the sound's length - the fix for # phones that record at a variable frame rate. $worker = [IO.File]::ReadAllText((Join-Path $out 'untrunc-worker.js')) $from = "`t""s"": [""-s""]," if (-not $worker.Contains($from)) { throw 'worker METHOD_ARGS not found: update the patch' } $worker = $worker.Replace($from, "$from`n`t""sv"": [""-sv""],`n`t""s-sv"": [""-s"", ""-sv""],") $notice = "// Modified by johnmcm.com on 6 Oct 2026: added the ""sv"" and ""s-sv"" methods (untrunc's -sv,`n// with and without -s) to METHOD_ARGS. Otherwise as built from the engine commit in SOURCE.txt.`n" [IO.File]::WriteAllText((Join-Path $dest 'untrunc-worker.js'), $notice + $worker) # The published source: the engine as built (without its git history), plus FFmpeg. $pub = Join-Path $PSScriptRoot 'source' if (Test-Path $pub) { Remove-Item -Recurse -Force $pub } New-Item -ItemType Directory -Force $pub | Out-Null Remove-Item -Recurse -Force (Join-Path $src '.git') Copy-Item -Recurse $src (Join-Path $pub 'engine') $tar = Join-Path $pub 'ffmpeg-3.3.9.tar.xz' Invoke-WebRequest -Uri $FfmpegUrl -OutFile $tar -UseBasicParsing $sha = (Get-FileHash -Algorithm SHA256 $tar).Hash.ToLower() if ($sha -ne $FfmpegSha) { throw "FFmpeg tarball hash $sha, expected $FfmpegSha" } Get-ChildItem $dest | Format-Table Name, Length