How to extract the duration of a video file?


I am trying to extract the duration, as seen in File Explorer as ‘Length’, for some type of video files like MP4. I understand not all video formats, like FLV, exposed this attribute. Almost all articles on the web has ‘length’ attribute of ‘File’ within Powershell, but it actually is the ‘size’ in File Explorer.

I am still searching all over for these two seemingly confusing attributes. Any help is appreciated.


Length of a video or music file comes from a file tag. In Win Explorer the details tab is reading the tag. There is a script that includes a function get-filemetadata which will give you all the tag info. I just used this function on an .mp4 and it give the length, bitrate, all the info you see on the details tab in Win Explorer.



The script is from soon to be retired Scripting Guy at Microsoft. Download, unblock file, and dot source the ps1 into powershell and try.

The info you are looking for is in the file tag. There’s a nice function create by the scripting guy that will get the info you want in powershell. Get-FileMetaData