Question about .mov file durations

I have a script which will present a folder of movies in succession for me. However, I have to make it skip .mov files. The reason is that they don’t return their duration to me properly.

I have it set up to close the current window, open the next file in the list, get the movie duration (which returns in miliseconds or something odd like that). Anyway, I have the script do the math to the duration returned and set that as a delay time so that the scrip tells Quicktime player to play the movie and then it pauses for the duration of the movie and then it continues on to close the current movie and open the next one.

The problem is that when I open a .mov file it gives me a duration of like 104 or 83 or some other tiny number. I can’t seem to find a correlation between the duration it returns and the actual length of the movie. I’ve opened and retrieved the duration for several separate files and divided the reported duration by the number of actual seconds in the movie and I get a different result for each.

So is there a correlation between the duration returned for a .mov file and the actual running time? Something I’m missing somehow?

With the .mov files I have, the “Duration” shown in the “Movie Info” window can be reproduced in AppleScript by dividing the ‘duration’ by the ‘time scale’. The display in the Info window follows the convention hours:minutes:seconds.frames, where there are 30 frames to a second. Here’s a test script:

tell application "QuickTime Player"
	set {duration:dur, time scale:tscale} to front movie
end tell

set runningTime to dur / tscale
set hr to text 2 thru 3 of ((100 + runningTime div hours) as string)
set min to text 2 thru 3 of ((100 + runningTime mod hours div minutes) as string)
set sec to text 2 thru 3 of ((100 + runningTime mod minutes div 1) as string)
set frm to text 2 thru 3 of ((100 + runningTime mod 1 * 30) as string)
set displayedDuration to hr & ":" & min & ":" & sec & "." & frm

display dialog "Running Time: " & runningTime & " seconds" & return & ¬
	"Displayed duration: " & displayedDuration

If this displays the right results for your movies too, you’ll be interested in the ‘runningTime’ figure for your delay.

I don’t worry about the durations, I just use the “playing” property to see if a movie is still playing before closing and moving on to the next one (note, this hasn’t been tested on 9/Classic but it should work):

set source_folder to (choose folder with prompt "Chose the folder containing your movies:") as Unicode text
set the_movies to (list folder (source_folder as alias) without inivisibles)

tell application "QuickTime Player"
	repeat with this_movie in the_movies
		open ((source_folder & this_movie) as alias)
		tell movie 1
			repeat while playing = true
				delay 0.1 --in Mac OS 9 or OS X 10.2, change this to: delay 1
			end repeat
		end tell
	end repeat
end tell


I guess it would be less intensive to just do one delay for the entire length of the movie. This should work:

tell application "QuickTime Player"
	tell front movie
		delay (duration div time scale)
	end tell
end tell


Yeah, that’s what I do is set the delay for the duration of the movie and it works except for the mov files. I’ll try the two suggestions given here. If classic quicktime responds to the “playing” check then I can just have it delay for a couple of seconds so it won’t be too intense on the processor while playing.

My script used to return a duration prior to upgrading to Tiger/QT 7 but now it doesn’t. I get an error instead that says “Can’t make <> of application Quicktime Player into type reference.”

Here is the code I’m using. This used to work fine with OS 10.3.9 and QT 6.5.2:

tell application "QuickTime Player"
	--this part opens the HREF text file as a movie
	set urlMovie to choose file with prompt "Please locate your HREF file:"
	open urlMovie

	--we need to know the duration of the movie so we can compare it 
	set urlDuration to the duration

	--copy contents of urlMovie and close it
	select all urlMovie
	copy movie 1
	close movie 1 saving no

	--open the recorded movie:
	set mainMovie to choose file of type "MooV" with prompt "Find your recorded movie:"
	open mainMovie

	--get the duration of this movie	
	set mainDuration to the duration
	--if recorded movie is longer than urlMovie then trim recorded movie
	if mainDuration > urlDuration then set mainDuration to (mainDuration - urlDuration)
end tell

Any references to the duration of the movie throw an error. It seems that it can no longer get the properties of a QT movie. I’ve also seen this occur with movie size. Any help appreciated!

That’s because you aren’t referencing any movies in those statements.