Last active
November 10, 2024 08:20
-
-
Save go2tom42/8fe864e4d455bd0592665adcf63a3c0f to your computer and use it in GitHub Desktop.
Change framerate for OGM Chapter files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Sync-Chapters { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory=$false)] | |
[double]$SourceFPS, | |
[Parameter(Mandatory=$false)] | |
[double]$TargetFPS, | |
[Parameter(Mandatory=$false)] | |
[double]$milliseconds, | |
[Parameter(Mandatory=$true)] | |
$file | |
) | |
$file = get-childitem -literalpath $file | |
$content = Get-Content -literalpath $file | |
if ($SourceFPS -and $TargetFPS) { | |
if (-not $SourceFPS -or -not $TargetFPS) { | |
Write-Error "Parameters `$SourceFPS and `$TargetFPS are required for this process." | |
return | |
} | |
for($i=0; $i -le $content.Length; ++$i) | |
{ | |
if($content[$i] | Select-String -Pattern "\d+:\d+:\d+\.\d+") | |
{ | |
$name = $content[$i].Split("=")[0] | |
$time = $content[$i].Split("=")[1] | |
$time_timespan = ([datetime] $time).TimeOfDay | |
$diff = $SourceFPS / $TargetFPS | |
$new_time = "{0:hh\:mm\:ss\.fff}" -f ($time_timespan * $diff) | |
$content[$i] = $name + "=" + $new_time | |
} | |
} | |
$content | Set-Content (join-path $($file.DirectoryName) "$($file.basename).FIXED$($file.extension)") | |
} elseif ($milliseconds) { | |
if (-not $milliseconds) { | |
Write-Error "`$milliseconds is required for this process." | |
return | |
} | |
for($i=0; $i -le $content.Length; ++$i) | |
{ | |
if($content[$i] | Select-String -Pattern "\d+:\d+:\d+\.\d+") | |
{ | |
if ($i -gt 0) { | |
$name = $content[$i].Split("=")[0] | |
$time = $content[$i].Split("=")[1] | |
$time_timespan = ([datetime] $time).TimeOfDay | |
$new_time = "{0:hh\:mm\:ss\.fff}" -f ($time_timespan.add([System.TimeSpan]::FromMilliseconds($milliseconds))) | |
$content[$i] = $name + "=" + $new_time | |
} | |
} | |
} | |
$content | Set-Content (join-path $($file.DirectoryName) "$($file.basename).FIXED$($file.extension)") | |
} else { | |
Write-Error "You must specify parameters for either Process 1 (`$SourceFPS and `$TargetFPS) or Process 2 (`$milliseconds)." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment