Question: Length of all videos in a folder

JADWil

macrumors newbie
Original poster
Sep 4, 2014
6
0
Hi guys,
Sorry if this is not the place to post my question, but I didn't know where else to post it.

Anyways, I have a folder that has around a 100 videos, each has a different length, and I would like to see how long are they all together. So is there anyway that I figure that out quickly?? I need to know how long they are, and I really don't want to look at each one individually


Thanks
 

Gregg2

macrumors 603
May 22, 2008
5,809
344
Milwaukee, WI
Highlight the files, then go to Edit(or is it File?) > Get Info

Now hold down the Option key. Get Info changes to Show Inspector. It will show you the total size.

OOps! read that incorrectly. But size does matter, sometimes. :eek:
 
Last edited:

JADWil

macrumors newbie
Original poster
Sep 4, 2014
6
0
Thank you all, I actually used this:

If they are of a similar type then you may be able to get a pretty good estimate by the file size.
I just added the size of the longest 5 videos and divided their size by their length then multiplied it by the size of all the videos. that should be very close to their total length…. I have 227hrs of medical videos to watch :S it's going to be hectic!!
 

Tomorrow

macrumors 604
Mar 2, 2008
7,114
1,246
Always a day away
Thank you all, I actually used this:



I just added the size of the longest 5 videos and divided their size by their length then multiplied it by the size of all the videos. that should be very close to their total length…. I have 227hrs of medical videos to watch :S it's going to be hectic!!
The only possible snag here is that if the videos all use different encryption or bitrates, your calculation will be off.
 

JADWil

macrumors newbie
Original poster
Sep 4, 2014
6
0
The only possible snag here is that if the videos all use different encryption or bitrates, your calculation will be off.
hmm.. I honestly tried to play around with VLC like you said, it wouldn't give me a total time. I added the videos to a playlist, I also added them to VLC library, but nothing!! Is there a way to make VLC show me the total time??
 

kryten2

macrumors 6502a
Mar 17, 2012
995
59
Belgium
Try this :

Code:
-- time the following operation:
--set start_time to (time of (current date)) -- start timing

set this_folder to (choose folder with prompt "Pick the folder containing the video files to process:") as string

set video_ext_list to {"3g2", "3gp", "3gp2", "3gpp", "3mm", "60d", "aep", "ajp", "amv", "asf", "asx", "avb", "avi", "avs", "bik", "bix", "box", "byu", "cvc", "dce", "dif", "dir", "divx", "dv", "dvr-ms", "dxr", "eye", "fcp", "flc", "fli", "flv", "flx", "gl", "grasp", "gvi", "gvp", "ifo", "imovieproject", "ivf", "ivs", "izz", "izzy", "lsf", "lsx", "m1v", "m2v", "m4e", "m4u", "m4v", "mjp", "mkv", "moov", "mov", "movie", "mp4", "mpe", "mpeg", "mpg", "mpv2", "msh", "mswmm", "mvb", "mvc", "nvc", "ogm", "omf", "prproj", "prx", "qt", "qtch", "rm", "rmvb", "rp", "rts", "sbk", "scm", "smil", "smv", "spl", "srt", "ssm", "svi", "swf", "swi", "tivo", "ts", "vdo", "vf", "vfw", "vid", "viewlet", "viv", "vivo", "vob", "vro", "wm", "wmd", "wmv", "wmx", "wvx", "yuv"}


tell application "Finder"
	set these_files to ((files of folder this_folder whose name extension is in video_ext_list) as alias list)
end tell

set filesCount to count of these_files

set total_duration_of_files_in_seconds to ""
set files_with_no_duration to 0

repeat with i from 1 to filesCount
	set this_file to (item i of my these_files)
	set this_info to info for this_file
	if visible of this_info is true and alias of this_info is false then
		-- insert actions here for: this_file
		set this_file_duration_in_seconds to do shell script "mdls -name kMDItemDurationSeconds -raw -nullMarker 0 " & quoted form of POSIX path of this_file
		if this_file_duration_in_seconds is not 0 then
			set total_duration_of_files_in_seconds to total_duration_of_files_in_seconds + this_file_duration_in_seconds
		else
			set files_with_no_duration to files_with_no_duration + 1
		end if
	end if
end repeat

set total_duration_in_hms to do shell script " echo " & total_duration_of_files_in_seconds & " | awk '{printf \"%03d:%02d:%02d\",$0/3600,$0%3600/60,$0%60}'"

(*
set end_time to (time of (current date)) -- stop timing.
set elapsed_time to end_time - start_time

log "2. elapsed_time is is " & elapsed_time & " seconds."
*)

display dialog "Files processed : " & (count of these_files) & return & "Files without duration : " & files_with_no_duration & return & "Total duration of " & (count of these_files) - files_with_no_duration & " files in h:m:s : " & total_duration_in_hms with title "Length of all videos in a folder" buttons {"OK"} default button 1
Note : Do not use the script on a folder with hundreds or more files. For your purpose of about 100 files it should be ok.
 

Attachments

matrix07

macrumors 601
Jun 24, 2010
4,918
1,422
hmm.. I honestly tried to play around with VLC like you said, it wouldn't give me a total time. I added the videos to a playlist, I also added them to VLC library, but nothing!! Is there a way to make VLC show me the total time??
Oh, you want total time of ALL files. I thought you want total time of EACH file.
 

UTkarshBRo

macrumors newbie
May 1, 2018
2
0
India
Try this :

Code:
-- time the following operation:
--set start_time to (time of (current date)) -- start timing

set this_folder to (choose folder with prompt "Pick the folder containing the video files to process:") as string

set video_ext_list to {"3g2", "3gp", "3gp2", "3gpp", "3mm", "60d", "aep", "ajp", "amv", "asf", "asx", "avb", "avi", "avs", "bik", "bix", "box", "byu", "cvc", "dce", "dif", "dir", "divx", "dv", "dvr-ms", "dxr", "eye", "fcp", "flc", "fli", "flv", "flx", "gl", "grasp", "gvi", "gvp", "ifo", "imovieproject", "ivf", "ivs", "izz", "izzy", "lsf", "lsx", "m1v", "m2v", "m4e", "m4u", "m4v", "mjp", "mkv", "moov", "mov", "movie", "mp4", "mpe", "mpeg", "mpg", "mpv2", "msh", "mswmm", "mvb", "mvc", "nvc", "ogm", "omf", "prproj", "prx", "qt", "qtch", "rm", "rmvb", "rp", "rts", "sbk", "scm", "smil", "smv", "spl", "srt", "ssm", "svi", "swf", "swi", "tivo", "ts", "vdo", "vf", "vfw", "vid", "viewlet", "viv", "vivo", "vob", "vro", "wm", "wmd", "wmv", "wmx", "wvx", "yuv"}


tell application "Finder"
    set these_files to ((files of folder this_folder whose name extension is in video_ext_list) as alias list)
end tell

set filesCount to count of these_files

set total_duration_of_files_in_seconds to ""
set files_with_no_duration to 0

repeat with i from 1 to filesCount
    set this_file to (item i of my these_files)
    set this_info to info for this_file
    if visible of this_info is true and alias of this_info is false then
        -- insert actions here for: this_file
        set this_file_duration_in_seconds to do shell script "mdls -name kMDItemDurationSeconds -raw -nullMarker 0 " & quoted form of POSIX path of this_file
        if this_file_duration_in_seconds is not 0 then
            set total_duration_of_files_in_seconds to total_duration_of_files_in_seconds + this_file_duration_in_seconds
        else
            set files_with_no_duration to files_with_no_duration + 1
        end if
    end if
end repeat

set total_duration_in_hms to do shell script " echo " & total_duration_of_files_in_seconds & " | awk '{printf \"%03d:%02d:%02d\",$0/3600,$0%3600/60,$0%60}'"

(*
set end_time to (time of (current date)) -- stop timing.
set elapsed_time to end_time - start_time

log "2. elapsed_time is is " & elapsed_time & " seconds."
*)

display dialog "Files processed : " & (count of these_files) & return & "Files without duration : " & files_with_no_duration & return & "Total duration of " & (count of these_files) - files_with_no_duration & " files in h:m:s : " & total_duration_in_hms with title "Length of all videos in a folder" buttons {"OK"} default button 1
Note : Do not use the script on a folder with hundreds or more files. For your purpose of about 100 files it should be ok.

Your script is far more useful than anything on internet bro...just request to add one more feature in this awesome thing,
i doesn't want to select folder everytime to know video length of all in it...i just want to right click on any my folder and run your script as services to know total duration. Please modify your apple script accordingly to that...!!! Big big thanks in advance...!!! @kryten2
 
Last edited:

KarBar110

macrumors newbie
Sep 17, 2019
1
0
Try this :

Code:
-- time the following operation:
--set start_time to (time of (current date)) -- start timing

set this_folder to (choose folder with prompt "Pick the folder containing the video files to process:") as string

set video_ext_list to {"3g2", "3gp", "3gp2", "3gpp", "3mm", "60d", "aep", "ajp", "amv", "asf", "asx", "avb", "avi", "avs", "bik", "bix", "box", "byu", "cvc", "dce", "dif", "dir", "divx", "dv", "dvr-ms", "dxr", "eye", "fcp", "flc", "fli", "flv", "flx", "gl", "grasp", "gvi", "gvp", "ifo", "imovieproject", "ivf", "ivs", "izz", "izzy", "lsf", "lsx", "m1v", "m2v", "m4e", "m4u", "m4v", "mjp", "mkv", "moov", "mov", "movie", "mp4", "mpe", "mpeg", "mpg", "mpv2", "msh", "mswmm", "mvb", "mvc", "nvc", "ogm", "omf", "prproj", "prx", "qt", "qtch", "rm", "rmvb", "rp", "rts", "sbk", "scm", "smil", "smv", "spl", "srt", "ssm", "svi", "swf", "swi", "tivo", "ts", "vdo", "vf", "vfw", "vid", "viewlet", "viv", "vivo", "vob", "vro", "wm", "wmd", "wmv", "wmx", "wvx", "yuv"}


tell application "Finder"
    set these_files to ((files of folder this_folder whose name extension is in video_ext_list) as alias list)
end tell

set filesCount to count of these_files

set total_duration_of_files_in_seconds to ""
set files_with_no_duration to 0

repeat with i from 1 to filesCount
    set this_file to (item i of my these_files)
    set this_info to info for this_file
    if visible of this_info is true and alias of this_info is false then
        -- insert actions here for: this_file
        set this_file_duration_in_seconds to do shell script "mdls -name kMDItemDurationSeconds -raw -nullMarker 0 " & quoted form of POSIX path of this_file
        if this_file_duration_in_seconds is not 0 then
            set total_duration_of_files_in_seconds to total_duration_of_files_in_seconds + this_file_duration_in_seconds
        else
            set files_with_no_duration to files_with_no_duration + 1
        end if
    end if
end repeat

set total_duration_in_hms to do shell script " echo " & total_duration_of_files_in_seconds & " | awk '{printf \"%03d:%02d:%02d\",$0/3600,$0%3600/60,$0%60}'"

(*
set end_time to (time of (current date)) -- stop timing.
set elapsed_time to end_time - start_time

log "2. elapsed_time is is " & elapsed_time & " seconds."
*)

display dialog "Files processed : " & (count of these_files) & return & "Files without duration : " & files_with_no_duration & return & "Total duration of " & (count of these_files) - files_with_no_duration & " files in h:m:s : " & total_duration_in_hms with title "Length of all videos in a folder" buttons {"OK"} default button 1
Note : Do not use the script on a folder with hundreds or more files. For your purpose of about 100 files it should be ok.
[doublepost=1568774359][/doublepost]Hi, I need to do this too, but am not familiar with what exactly to do with this code. I tried researching "how to run a script on mac" but all the search results seem to want to tell me how to record an action. Where do I enter this to make it "go"?
 

vkd

macrumors 6502a
Sep 10, 2012
870
275
hmm.. I honestly tried to play around with VLC like you said, it wouldn't give me a total time. I added the videos to a playlist, I also added them to VLC library, but nothing!! Is there a way to make VLC show me the total time??
Hm. I'm using VLC Player 2.2.8 (The Luggage). If I drag some files to it, creating a playlist, the VLC window has the Title, Artist and Duration listed by default in the Playlist. Directly above the playlist there is a black bar with a Search field at the RH side. On the LH side of this bar, which is directly under the grey header bar with the 3 coloured 'traffic light' icons in the LH corner (Close, Minimise, Maximise), it is written 'Playlist -- xx:xx:xx', where xx:xx:xx is the total playing time that the app has calculated for that playlist.
 

HDFan

macrumors 65816
Jun 30, 2007
1,487
361
On the LH side of this bar, which is directly under the grey header bar with the 3 coloured 'traffic light' icons in the LH corner (Close, Minimise, Maximise), it is written 'Playlist -- xx:xx:xx', where xx:xx:xx is the total playing time that the app has calculated for that playlist.
Screen Shot 2019-09-18 at 10.39.36 PM.png
 
  • Like
Reactions: vkd

UTkarshBRo

macrumors newbie
May 1, 2018
2
0
India
[doublepost=1568774359][/doublepost]Hi, I need to do this too, but am not familiar with what exactly to do with this code. I tried researching "how to run a script on mac" but all the search results seem to want to tell me how to record an action. Where do I enter this to make it "go"?
Hey...even though this script is not perfect but if you try then
-Open "Apple Script Editor" from your application tray.
-Paste this code
-Save this script as "Application" at wherever location you want to save
-Then open application and prompt will say "Choose Folder"
-Now choose the folder which contains video files and you want to know total duration
-it will show you the duration.

Note- It doesn't detect subfolder, So you have to make operation separately on each folder.

Thanks to kryten2 anyway.