[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$InputPath, [string]$OutputDir = 'dash', [ValidateRange(2, 30)] [int]$SegmentSeconds = 4, [ValidateRange(0, 51)] [int]$Crf = 20, [switch]$Force ) $ErrorActionPreference = 'Stop' if (-not (Get-Command ffmpeg -ErrorAction SilentlyContinue)) { throw 'ffmpeg не найден в PATH. Установите FFmpeg.' } if (-not (Test-Path -LiteralPath $InputPath -PathType Leaf)) { throw "Входной файл не найден: $InputPath" } $source = (Resolve-Path -LiteralPath $InputPath).Path $out = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($OutputDir) if (-not (Test-Path -LiteralPath $out)) { New-Item -ItemType Directory -Path $out -Force | Out-Null } $manifest = Join-Path $out 'manifest.mpd' $oldSegments = @(Get-ChildItem -LiteralPath $out -Filter '*.m4s' -File -ErrorAction SilentlyContinue) if ((-not $Force) -and ((Test-Path -LiteralPath $manifest) -or $oldSegments.Count -gt 0)) { throw 'В папке уже есть DASH-файлы. Добавьте -Force для перезаписи.' } $arguments = @( '-hide_banner', '-nostdin', '-y', '-i', $source, '-c:v', 'libx264', '-preset', 'medium', '-crf', "$Crf", '-pix_fmt', 'yuv420p', '-c:a', 'aac', '-b:a', '160k', '-f', 'dash', '-seg_duration', "$SegmentSeconds", '-use_template', '1', '-use_timeline', '1', $manifest ) Write-Host "DASH: $source -> $manifest" & ffmpeg @arguments if ($LASTEXITCODE -ne 0) { throw "ffmpeg завершился с кодом $LASTEXITCODE" } $count = @(Get-ChildItem -LiteralPath $out -Filter '*.m4s' -File).Count Write-Host "Готово: $manifest, сегментов: $count"