我想用PowerShell提取几个mp4文件的持续时间。我找到了一个满足我要求的脚本,但是使用此脚本,显示的持续时间为HH:mm:ss,并且我希望精确的持续时间比秒更精确,例如毫秒或HH:mm:ss:SSS。 / p>
有人可以帮助我吗?有办法吗? 我找到的脚本如下:
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
}
}
}
}
提供您的视频目录
Get-VideoDetails "C:\VIDS"
答案 0 :(得分:1)
使用MediaInfo命令行(CLI)构建,您可以尝试以下操作:
$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