Created
April 16, 2019 21:30
-
-
Save VladRez/8208b834dc82abbc67e5bc66f710e15a to your computer and use it in GitHub Desktop.
Display video/audio length in powershell
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
| $Folder = 'C:\path\to\media\'; | |
| $sec = 0 | |
| $min = 0 | |
| $hr = 0 | |
| $len = @() | |
| Get-ChildItem -Recurse | ForEach-Object { | |
| $File = $_.Name; | |
| # Write-Output $File | |
| $Duration = 27; | |
| $objShell = New-Object -ComObject Shell.Application | |
| $objFolder = $objShell.Namespace($Folder) | |
| $objFile = $objFolder.ParseName($File) | |
| $Length = $objFolder.GetDetailsOf($objFile, $Duration) | |
| #Write-Output $Length | |
| $sec += [int]$Length.Substring(6,2) | |
| if ($sec -ge 60){ | |
| $min += 1 | |
| $sec %= 60 | |
| } | |
| $min += [int]$Length.Substring(3,2) | |
| if ($min -ge 60){ | |
| $hr += 1 | |
| $min %= 60 | |
| } | |
| $hr += [int]$Length.Substring(0,2) | |
| $Object = New-Object System.Object | |
| $Object | Add-Member -type NoteProperty -Name FileName -Value $_.Name; | |
| $Object | Add-Member -type NoteProperty -Name Length -Value $Length; | |
| $len += $object | |
| } | |
| $Total = New-TimeSpan -Hour $hr -Minute $min -Seconds -$sec | |
| $Object = New-Object System.Object | |
| $Object | Add-Member -type NoteProperty -Name Length -Value $Total; | |
| $Object | Add-Member -type NoteProperty -Name FileName -Value "TOTAL TIME"; | |
| $len += $Object | |
| $len | |
| # FileName Length | |
| # -------- ------ | |
| # 01.video-a.mp4 00:04:21 | |
| # 02.video-b.mp4 00:09:33 | |
| # 03.video-c.mp4 00:10:34 | |
| # 04.video-d.mp4 00:12:05 | |
| # 05.video-e.mp4 00:05:25 | |
| # 06.video-f.mp4 00:06:41 | |
| # TOTAL TIME 00:47:21 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment