Ivan Yosifov
Ivan Yosifov

Reputation: 59

How to read length of video file from cmd

I have a bunch of mp4 files in a folder and I want to create a text file with all the names and the length of the files as in:

01_Welcome.mp4 00.01.23
02_Tools.mp4 00.03.12

I know how to read the names of the files buy how do I get the length attribute? When I click a file the length appears in the status bar, so there should be a way to read that property. And I would like to do it from the command line, not through a third-party package.

Upvotes: 1

Views: 4026

Answers (2)

Przemek D
Przemek D

Reputation: 664

In Windows' PowerShell you can do the following to extract length of a single media file:

$Folder = 'C:\Path\To\Parent\Folder'
$File = 'Video.mp4'
$LengthColumn = 27
$objShell = New-Object -ComObject Shell.Application 
$objFolder = $objShell.Namespace($Folder)
$objFile = $objFolder.ParseName($File)
$Length = $objFolder.GetDetailsOf($objFile, $LengthColumn)

Iteration over the folder content is left as an exercise for the reader.

Source

Upvotes: 0

Anptk
Anptk

Reputation: 1123

In ubuntu there you can

 ffmpeg -i myvideo 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,//

But in Windows MediaInfo is the one option

Upvotes: 2

Related Questions