[CmdletBinding()]
param(
  [Parameter(Mandatory = $true)][string]$InputMkv,
  [Parameter(Mandatory = $true)][string]$RpuFile,
  [Parameter(Mandatory = $true)][string]$OutputReport,
  [string]$Ffmpeg = "C:\ffmpeg_latest\ffmpeg.exe",
  [string]$DoviTool = "",
  [string]$SmartCutCli = ""
)

$projectRoot = Split-Path -Parent $PSScriptRoot
if (-not (Test-Path -LiteralPath $Ffmpeg -PathType Leaf)) { throw "Missing ffmpeg: $Ffmpeg" }
if (-not (Test-Path -LiteralPath $InputMkv -PathType Leaf)) { throw "Missing MKV: $InputMkv" }
$tempHevc = Join-Path ([System.IO.Path]::GetTempPath()) ("smartcut-mkv-" + [guid]::NewGuid().ToString("N") + ".hevc")
try {
  & $Ffmpeg -y -i $InputMkv -map 0:v:0 -c copy -bsf:v hevc_mp4toannexb -f hevc $tempHevc
  if ($LASTEXITCODE -ne 0) { throw "ffmpeg HEVC extraction failed with exit code $LASTEXITCODE" }
  & (Join-Path $projectRoot "tools\verify-rpu-roundtrip.ps1") -InputHevc $tempHevc -RpuFile $RpuFile -OutputReport $OutputReport -DoviTool $DoviTool -SmartCutCli $SmartCutCli
  exit $LASTEXITCODE
}
finally {
  Remove-Item -LiteralPath $tempHevc -Force -ErrorAction SilentlyContinue
}
