Skip to content

Instantly share code, notes, and snippets.

@kerbrose
Last active April 6, 2018 05:29
Show Gist options
  • Save kerbrose/9853e9330ed85d7ef92ebdec4aa70c2f to your computer and use it in GitHub Desktop.
Save kerbrose/9853e9330ed85d7ef92ebdec4aa70c2f to your computer and use it in GitHub Desktop.
this script will help you to get duration of video in the directory
Function Get-VideoDetails {
param ($targetDirectory)
$LengthColumn = 27
$objShell = New-Object -ComObject Shell.Application
$total_duration = [timespan] '00:00:00'
Get-ChildItem -LiteralPath $targetDirectory -Include *.mp4 -Recurse -Force | ForEach {
if ($_.Extension -eq ".mp4"){
$objFolder = $objShell.Namespace($_.DirectoryName)
$objFile = $objFolder.ParseName($_.Name)
$Duration = $objFolder.GetDetailsOf($objFile, $LengthColumn)
$time_span = [timespan]$Duration
$total_duration += $time_span
New-Object PSObject -Property @{
Name = $_.Name
Duration = $time_span
}
}
}
Write-Output $total_duration.ToString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment