In Windows the file metadata can be accessed directly using Shell COM object's Folder.GetDetailsOf() method without installing any tools. That's how Windows Explorer shows the file details as you've always seen
That means you can use any languages that support COM objects like PowerShell, VBS, Jscript... to get the video duration. Here's an example in PowerShell:
You can use the following PowerShell script
$path = $Args[0]
$columnNumber = 27 # Magic number, may be different, see below
$shell = New-Object -COMObject Shell.Application
$folder = Split-Path $path
$file = Split-Path $path -Leaf
$shellfolder = $shell.Namespace($folder)
$shellfile = $shellfolder.ParseName($file)
$duration = $shellfolder.GetDetailsOf($shellfile, 27) # Duration in hh:mm:ss format
[timespan]::Parse($duration).TotalSeconds
Save it as a *.ps1 file, e.g. duration.ps1, then call it like this
duration.ps1 path\to\video\file
This works for any types that has duration that Windows can read. You can find more details in
Of course because it uses Shell.Application, you can use any WScript languages to achieve the same purpose. For example here's a hybrid batch/Jscript version, just save it as a normal *.bat file and pass the video file path to it:
@if (@CodeSection == @Batch) @then
@echo off
cscript //e:jscript //nologo "%~f0" %1
exit /b
@end
// JScript Section
var filepath = WScript.Arguments.Item(0);
var slash = filepath.lastIndexOf('\');
var folder = filepath.substring(0, slash);
var file = filepath.substring(slash + 1);
var shell = new ActiveXObject("Shell.Application");
var shellFolder = shell.NameSpace(folder);
shellfile = shellFolder.ParseName(file);
var duration = shellFolder.GetDetailsOf(shellfile, 27);
WScript.Echo(duration);
You'll also need to parse the time like how I used [timespan] above, because the output is in hh:mm:ss form instead of only seconds, but that's trivial.
Note that the column number 27 above might be changed in future versions of Windows. If it's changed you can find the new magic number by running this in PowerShell:
$objFolder = (New-Object -ComObject Shell.Application).Namespace('c:\')
$(for ($columnNumber = 0; $columnNumber -lt 500; ++$columnNumber)
{
$columnName = $objFolder.GetDetailsOf($objFolder.Items, $columnNumber)
if ($columnName)
{
[PsCustomObject]@{
MagicNum = ([string]$columnNumber).PadLeft(3);
ColumnName = $columnName
}
}
}) | where { $_.ColumnName -like "*duration*" -or $_.ColumnName -like "*len*" }
Sample output on my PC:
MagicNum ColumnName
-------- ----------
27 Length
43 Duration
165 Filename
262 Focal length
263 35mm focal length
265 Lens maker
266 Lens model