How to show the duration time of several mp4 files

I want to extract the duration time of several mp4 files with PowerShell. I found a script that makes what I want, but with this scripts the duration shown is HH:mm:ss, and I want the exact duration time with more precision than seconds, like miliseconds or maybe HH:mm:ss:SSS.

Someone could help me? There is a way to do that? The script I found is the following:

Function Get-VideoDetails {
    param ($targetDirectory)
    $LengthColumn = 27
    $objShell = New-Object -ComObject Shell.Application
    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)
            New-Object PSObject -Property @{
                Name = $_.Name
                Duration = $Duration
            }
        }
    }
}

Supply your video directory

Get-VideoDetails "C:\VIDS"

Upvotes: 0

Views: 2137

Answers (1)

Bill
Bill

Reputation: 21

Using the MediaInfo command line (CLI) build you can try something like this:

$VideoDuration = [math]::Round(((C:\MediaInfoCLI\mediainfo '--Output=Video;%Duration%' $File.FullName) / 1000), 3)     # MediaInfo reported Video duration in decimal seconds

$AudioDuration = [math]::Round(((C:\MediaInfoCLI\mediainfo '--Output=Audio;%Duration%' $File.FullName) / 1000), 3)     # MediaInfo reported Audio duration in decimal seconds

Upvotes: 2

Related Questions