代码示例
[CmdletBinding()]
Param(
[string] $dirPath
)
Write-Host ">>> ${dirPath}"
$videos = Get-ChildItem -Path $dirPath -Recurse -Include *.mp4,*.avi,*.mkv,*.mov,*.wmv,*.flv,*.webm,*.mpg,*.mpeg,*.m4v,*.3gp,*.ts,*.vob,*.ogv,*.m2ts,*.mts,*.divx,*.xvid,*.rmvb,*.asf,*.qt,*.fv,*.mxf,*.mpv,*.mp2,*.mpe,*.mpa,*.m2v,*.m1v,*.mod,*.tod,*.dvr-ms,*.wtv,*.ogm,*.rm,*.ram,*.mk3d,*.mks,*.nsv,*.dts,*.ac3,*.eac3,*.aac,*.wma,*.wav,*.flac,*.ape,*.alac,*.opus,*.mka
$totalDuration = 0
$totalVideos = $videos.Count
$cursorLeft = [Console]::CursorLeft
$cursorTop = [Console]::CursorTop
$i = 1
foreach ($video in $videos) {
Write-Host "[${i}/${totalVideos}] -> " $video.FullName -NoNewline
Write-Host -NoNewline (" " * [Console]::CursorLeft)
[Console]::SetCursorPosition($cursorLeft, $cursorTop)
$i = $i + 1
$duration = & ffprobe.exe -i $video.FullName -show_entries format=duration -v quiet -of csv="p=0"
$durationSeconds = [math]::Round($duration)
$totalDuration += $durationSeconds
}
Write-Host ""
$ts = [TimeSpan]::FromSeconds($totalDuration)
Write-Host "Total duration of all videos in ${dirPath}: $($ts.Days) days, $($ts.Hours) hours, $($ts.Minutes) minutes, $($ts.Seconds) seconds"
使用方法
winget install Gyan.FFmpeg -l D:\Programs\Gyan\FFmpeg --accept-package-agreements
.\videos_total_time.ps1 -dirPath "G:\学习资料\图灵\5期"