Movie duration in QuickTime

Hi dear gurus,
Can you please tell me how can I know the duration of any movie that can be played in quicktime, without opening the movie?

I have been messing with the following code…


on open these_items
	tell application "Finder" to set sorted_items ¬
		to sort these_items by name
	activate
	repeat with i from 1 to the count of sorted_items
		set this_item to (item i of sorted_items)
		tell application "QuickTime Player"
			tell document this_item
				set MovieDuration to the duration
				display dialog "Movie duration = " & MovieDuration
			end tell
		end tell
	end repeat
end open

but this is not working…

This is driving me crazy!

Thanks for any help.

Model: PPC MacMini
AppleScript: leopard’s
Browser: Safari 523.10.6
Operating System: Mac OS X (10.5)

Hi,

it’s possible even without launching QuickTime Player


on open these_items
	repeat with oneItem in these_items
		tell application "System Events"
			try
				set q to QuickTime file (oneItem as text)
				set MovieDuration to duration of contents of q
				display dialog "Movie duration of " & name of q & " = " & MovieDuration
			end try
		end tell
	end repeat
end open

Hi, thanks! Almost perfect!
but your script gives me durations like 105400, 32657, etc.
what are these numbers? Frames? seconds?

How do I can have the duration in hours, minutes and seconds?

thanks!

I guessed, you will ask this :wink:

A little additional math is required


on open these_items
	repeat with oneItem in these_items
		tell application "System Events"
			try
				set q to QuickTime file (oneItem as text)
				tell (contents of q) to set {timeScale, theDuration} to {time scale, duration}
				tell (theDuration / timeScale) to set {hr, mn, sc} to {it div hours, it mod hours div minutes, it mod hours mod minutes div 1}
				display dialog "Movie duration of " & name of q & " = " & hr & ":" & mn & ":" & sc
			end try
		end tell
	end repeat
end open

PS: If you want also the number of frames like in SMTPE, then you need QuickTime Player for the frames information

Perfect !!!
You Are The Man!
Thanks!!!
If you need a Photoshop job (logo, or something) just let me know and I will make it free for you! :smiley:

HELO!
How I make this script to check the movie I want?

Model: mac pro
AppleScript: 118
Browser: Safari 6531.22.7
Operating System: Mac OS X (10.6)

Save the script as application and drop the movie(s) onto it

I have been using the code above to get the duration of a quicktime file but now that I have upgraded to Mavericks the line

set q to QuickTime file (theFile as text)

gives an error -10000

Does anyone know how to fix this in Mavericks?

Does anyone have a solution to finding the duration in Mavericks?

It seems that the QuickTime file class of System Events is broken in Mavericks.

A workaround is to open the files in QuickTime Player and get the data from there

Thank you. I have reported the issue to Apple.

Hopefully, they will fix it in a future release!

They might – but there’s a chance they may not. It’s possible that it’s broken because it depends on some of the old QuickTime code that has been removed in Mavericks.

I wonder if the command-line tool mils can get what you want from Spotlight data.