aboutsummaryrefslogtreecommitdiff
path: root/convert_sbs_to_half_sbs.ps1
diff options
context:
space:
mode:
authorPascal Dulieu <pascal@dulieu.uk>2026-04-21 21:15:02 +0100
committerPascal Dulieu <pascal@dulieu.uk>2026-04-21 21:23:53 +0100
commit7e25e7c9bd135f30b4aaeb608805cd77feef5f1d (patch)
tree0789d46b856351dcece6c0e71c8620f3a9a5128c /convert_sbs_to_half_sbs.ps1
Initial commitHEADmain
Made-with: Cursor
Diffstat (limited to 'convert_sbs_to_half_sbs.ps1')
-rw-r--r--convert_sbs_to_half_sbs.ps167
1 files changed, 67 insertions, 0 deletions
diff --git a/convert_sbs_to_half_sbs.ps1 b/convert_sbs_to_half_sbs.ps1
new file mode 100644
index 0000000..66fd426
--- /dev/null
+++ b/convert_sbs_to_half_sbs.ps1
@@ -0,0 +1,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 \ No newline at end of file