用 PowerShell 获取视频时长(无需安装 FFmpeg)

通过系统内置的 Shell.Application COM 对象读取视频文件的"长度"属性。

Windows视频COMPowerShell低风险
用 Shell.Application 的 Namespace + ParseName 打开视频文件,再以长度列索引(通常为 27)调用 GetDetailsOf。

01命令

命令
$ $sh=New-Object -ComObject Shell.Application; $f=$sh.Namespace('C:\Videos'); $v=$f.ParseName('clip.mp4'); $f.GetDetailsOf($v,27)

02作用说明

资源管理器为每个视频显示时长、宽高和比特率,这些全部可以通过 Windows 属性系统读取,完全不需要安装媒体工具。在多数 Windows 10/11 上"长度"列是索引 27,但建议先对单个文件扫描全部列确认。配合 Get-ChildItem 循环即可一次性获取整个文件夹中所有视频的时长。

03风险

风险低风险
使用条件Index of the Length column varies by Windows version; run the full GetDetailsOf scan first to find the right index
!注意: "长度"列的索引随 Windows 版本和语言而不同,写脚本前务必先验证索引。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • System.Media.Duration
    Microsoft Learn · vendor-doc · 2026-09-17
    依据: Defines the media duration property in 100ns units that Windows Explorer reads for video/audio files — the value GetDetailsOf exposes as a human-readable length.
  • FolderItem object (Shell)
    Microsoft Learn · vendor-doc · 2026-09-17
    依据: Documents Folder.ParseName / Folder.GetDetailsOf, the COM surface used to read a specific metadata column for a file.

最后验证: 2026-09-17 · 分类: 媒体

06相关方案