I can see the time length in Windows Explorer, but there are 124 files. I'd rather not have to add them up manually. I have ffmpeg and VLC also if that would help.
5 Answers
I tried to select all and click Properties > Details but it wouldn't show the total. OK I see that I had selected two VTT subtitle files. I deselected the VTT files and went to Properties > Details and now I see the total is 71 hours. (I don't know what a Windows bar is.)
- 6,196
Depending on the type of video file it is, but if it says a mp4 video file, then select the videos together by clicking one, +Ctrl, then another, then another until you are done all the while holding the Ctrl button down. Or Ctrl+A to select all videos in a folder. Then the total running time will show in the Windows details pane just as a single video file would.
I think this question is quite alike the one asked before at How to get video duration in seconds?
With bellow command you can get the duration of a given video file (e.g. file1.mp4):
ffmpeg -i file1.mp4 2>&1 | grep "Duration" | cut -f4 -d' ' | cut -f1 -d','
With for loop , it is easy to get duration of each file:
for f in *.mp4; do
ffmpeg -i $f 2>&1 | grep "Duration" | cut -f4 -d' ' | cut -f1 -d','
done
Then to sum them up by any external spreedsheet utility (e.g. Excel). If you insist to use command line to get the total, you can still refer to the method provided by this How to get video duration in seconds?, to covert each duration into seconds, then to add all seconds up.
EDIT:
As you mentioned Windows Explorer, I assume you are using Windows only and here bellow are pure Windows based (and ffmpeg as you mentioned already) solutions (you may need to provide path to ffmpeg):
for %f in (*.mp4) do @ffmpeg -i %f 2>&1 | findstr Duration > result.txt
The result looks like:
Duration: 00:00:18.20, start: 0.000000, bitrate: 17085 kb/s
Duration: 00:00:45.12, start: 0.000000, bitrate: 16913 kb/s
Duration: 00:00:41.93, start: 0.000000, bitrate: 17083 kb/s
Again, with Excel, you can easily split the duration part and sum them up. Or you can refer to https://stackoverflow.com/questions/4441827/windows-command-for-cutting-columns-from-a-text to use Windows command line only to get the duration only.
- 30,396
- 15
- 136
- 260
- 197
If you want to calculate the length programmatically then you can use this to get the duration of each file then sum up
function Get-VideoDuration {
param (
[string]$Path
)
$columnNumber = 27 # Adjust this number based on your system if needed
$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, $columnNumber) # Duration in hh:mm:ss format
[timespan]::Parse($duration)
}
function Get-TotalVideoDuration {
param (
[string[]]$Paths
)
[timespan]$totalDuration = 0
foreach ($path in $Paths) {
$totalDuration += Get-VideoDuration -Path $path
}
$totalDuration
}
Of course you can reuse the $shellfolder and $shellfolder objects to optimize for the case of getting files in a single folder. I'll leave that out of here for simplicity
To use it you can call like this
$videoFiles = @("C:\path\to\video1.mp4", "C:\path\to\video2.mp4", "C:\path\to\video3.mp4")
$totalSeconds = Get-TotalVideoDuration -Paths $videoFiles
Write-Output "Total duration for $videoFiles: $($totalSeconds.TotalSeconds))"
$videoFiles = Get-ChildItem C:\path*.mp4
$totalSeconds = Get-TotalVideoDuration -Paths $videoFiles
Write-Output "Total duration for $videoFiles: $($totalSeconds.TotalSeconds))"
- 30,396
- 15
- 136
- 260
I don't know why you all guys told him that 8 year ago.
to get your duration.
just go to your windows file explorer, select the directory your video is located.
move your mouse to the header of the file explorer window.
click right button, you'll get a header menu listing sizing options and a partial list of header label options.
move mouse to more and click it. this takes you to more labeling options. look for "length". thats the one you want, click it. it will tell you the duration of your video, unfortunately, it does not do that for gif videos.
you can move the length label to any position along the header.
hope this helps after eight years.