[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Path, [switch]$Recurse, [string[]]$Extensions = @('mp4', 'mkv', 'webm', 'mov', 'avi', 'm4v', 'ts'), [string]$Csv ) $ErrorActionPreference = 'Stop' foreach ($tool in @('ffmpeg', 'ffprobe')) { if (-not (Get-Command $tool -ErrorAction SilentlyContinue)) { throw "$tool не найден в PATH. Установите FFmpeg." } } if (-not (Test-Path -LiteralPath $Path -PathType Container)) { throw "Папка не найдена: $Path" } $root = (Resolve-Path -LiteralPath $Path).Path $wanted = $Extensions | ForEach-Object { $_.TrimStart('.').ToLowerInvariant() } $files = @( Get-ChildItem -LiteralPath $root -File -Recurse:$Recurse | Where-Object { $wanted -contains $_.Extension.TrimStart('.').ToLowerInvariant() } ) if ($files.Count -eq 0) { Write-Host 'Видеофайлы не найдены.' return } $results = foreach ($file in $files) { Write-Host "Проверка: $($file.FullName)" $probeOutput = & ffprobe -v error -show_entries format=duration -of default=nw=1:nk=1 $file.FullName 2>&1 $probeOk = $LASTEXITCODE -eq 0 $duration = 0.0 if ($probeOk) { $line = @($probeOutput | Where-Object { $_ -match '^[0-9]+([.][0-9]+)?$' } | Select-Object -First 1) if ($line.Count -gt 0) { $duration = [double]$line[0] } } $decodeOutput = & ffmpeg -v error -nostdin -i $file.FullName -f null - 2>&1 $decodeOk = $LASTEXITCODE -eq 0 $message = '' if (-not $probeOk) { $message = [string](@($probeOutput | Select-Object -First 1)[0]) } elseif (-not $decodeOk) { $message = [string](@($decodeOutput | Select-Object -First 1)[0]) } [pscustomobject]@{ File = $file.FullName SizeMB = [math]::Round($file.Length / 1MB, 2) DurationSec = [math]::Round($duration, 2) Status = if ($probeOk -and $decodeOk) { 'OK' } else { 'BROKEN' } Error = $message } } $results | Format-Table -AutoSize $broken = @($results | Where-Object { $_.Status -eq 'BROKEN' }) Write-Host ("Проверено: {0}, битых: {1}" -f $results.Count, $broken.Count) if ($Csv) { $results | Export-Csv -LiteralPath $Csv -NoTypeInformation -Encoding UTF8 Write-Host "Отчёт сохранён: $Csv" } if ($broken.Count -gt 0) { exit 1 }