← Back to Blog

Auto remux to get the time correct

Auto remux to get the time correct Script to run for estimations $shell = New-Object -ComObject Shell.Application $folderPath = (Get-Location).Path $folder = $shell.Namespace($folderPath) $videos = $folder.Items() | Where-Object {$_.Name -like "*.mp4"} | ForEach-Object

Auto remux to get the time correct

auto remux to 1

Script to run for estimations

$shell = New-Object -ComObject Shell.Application
                $folderPath = (Get-Location).Path
                $folder = $shell.Namespace($folderPath)
                
                $videos = $folder.Items() | Where-Object {$_.Name -like "*.mp4"} | ForEach-Object {
                    $file = $_
                    $lengthString = $folder.GetDetailsOf($file, 27)  # 27 is typically the index for Length
                
                    # Convert the length string to a TimeSpan object
                    $pattern = '(\d+):(\d{2}):(\d{2})'
                    $timeSpan = if ($lengthString -match $pattern) {
                        New-TimeSpan -Hours $matches[1] -Minutes $matches[2] -Seconds $matches[3]
                    } else {
                        New-TimeSpan -Seconds 0  # Default to 0 if no match
                    }
                
                    [PSCustomObject]@{
                        Name = $file.Name
                        Length = $lengthString
                        TimeSpan = $timeSpan
                    }
                }
                
                # Display the list sorted by duration
                $sortedVideos = $videos | Sort-Object TimeSpan
                $sortedVideos | Format-Table -AutoSize
                
                # Calculate and display the total duration
                $totalDuration = New-TimeSpan
                foreach ($video in $videos) {
                    $totalDuration += $video.TimeSpan
                }
                
                "Total Duration: $($totalDuration.ToString())"
                
                

Imported from rifaterdemsahin.com · 2024