1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
param(
[Parameter(Mandatory=$true)]
[string]$InputFile
)
function New-HalfFrameSBS {
param(
[string]$SbsFile,
[string]$OutputFile
)
Write-Host "Checking input file dimensions..." -ForegroundColor Yellow
try {
$probeOutput = & ffprobe -v quiet -print_format json -show_streams "`"$SbsFile`""
$probeJson = $probeOutput | ConvertFrom-Json
$videoStream = $probeJson.streams | Where-Object { $_.codec_type -eq "video" } | Select-Object -First 1
if ($videoStream) {
$width = $videoStream.width
$height = $videoStream.height
Write-Host "Input dimensions: ${width}x${height}" -ForegroundColor Cyan
} else {
Write-Host "Could not find video stream information" -ForegroundColor Red
}
} catch {
Write-Host "Error getting input dimensions: $($_.Exception.Message)" -ForegroundColor Red
$inputInfo = & ffmpeg -i "`"$SbsFile`"" 2>&1 | Select-String "Stream.*Video.*(\d+)x(\d+)"
if ($inputInfo -and $inputInfo.Matches.Groups.Count -ge 3) {
$width = $inputInfo.Matches.Groups[1].Value
$height = $inputInfo.Matches.Groups[2].Value
Write-Host "Input dimensions (fallback): ${width}x${height}" -ForegroundColor Cyan
}
}
$halfFrameArgs = @("-i", "`"$SbsFile`"", "-vsync", "vfr", "-vf", "`"scale=iw/2:ih,setdar=16/9`"", "-c:v", "libx264", "-profile:v", "main", "-level", "4.1", "-pix_fmt", "yuv420p", "-crf", "23", "-refs", "3", "-bf", "2", "-g", "30", "-keyint_min", "23", "-sc_threshold", "40", "-c:a", "aac", "-b:a", "192k", "-ar", "48000", "-ac", "2", "`"$OutputFile`"")
Write-Host "Running: ffmpeg $($halfFrameArgs -join ' ')" -ForegroundColor Gray
& ffmpeg $halfFrameArgs
if (Test-Path $OutputFile) {
Write-Host "Checking output file dimensions..." -ForegroundColor Yellow
try {
$probeOutput = & ffprobe -v quiet -print_format json -show_streams "`"$OutputFile`""
$probeJson = $probeOutput | ConvertFrom-Json
$videoStream = $probeJson.streams | Where-Object { $_.codec_type -eq "video" } | Select-Object -First 1
if ($videoStream) {
$outWidth = $videoStream.width
$outHeight = $videoStream.height
Write-Host "Output dimensions: ${outWidth}x${outHeight}" -ForegroundColor Cyan
}
} catch {
Write-Host "Error getting output dimensions: $($_.Exception.Message)" -ForegroundColor Red
$outputInfo = & ffmpeg -i "`"$OutputFile`"" 2>&1 | Select-String "Stream.*Video.*(\d+)x(\d+)"
if ($outputInfo -and $outputInfo.Matches.Groups.Count -ge 3) {
$outWidth = $outputInfo.Matches.Groups[1].Value
$outHeight = $outputInfo.Matches.Groups[2].Value
Write-Host "Output dimensions (fallback): ${outWidth}x${outHeight}" -ForegroundColor Cyan
}
}
}
if (-not (Test-Path $OutputFile)) {
throw "Failed to create half-frame SBS video"
}
Write-Host "Half-frame SBS creation completed" -ForegroundColor Green
}
$inputFileItem = Get-Item $InputFile
$OutputFile = Join-Path $inputFileItem.DirectoryName ($inputFileItem.BaseName + "-half-sbs.mp4")
New-HalfFrameSBS -SbsFile $InputFile -OutputFile $OutputFile
|