Converting Timecode to Frame Numbers

Hi

2 Questions

First QUESTION
in a text file I have the movie names and their timecode duration
I hope to convert the timecode duration to the equivalent frame count.
Every movie time base is 25 frames per seconds

My text file is as such
MOVIE1.MOV [TAB] 00:02:12:05
MOVIE2.MOV [TAB] 00:04:02:12
MOVIE3.MOV [TAB] 00:00:32:19

How to convert this to a new file as follows?

MOVIE1.MOV [TAB] XXXX Frames
and so on?

SECOND QUESTION
How to ask Quicktime Player 7 to open a movie file and place the playhead at a given frame?

thanks a lot

Dan

Hi.

For your first question:


set oldText to "MOVIE1.MOV [TAB] 00:02:12:05"

set {h, m, s, f} to words -4 thru -1 of oldText
set frameCount to (h * hours + m * minutes + s) * 25 + f
set newText to text 1 thru -12 of oldText & frameCount & " Frames"

Thank you, but how to scroll through the hundreds paragraphs in the file and create a new text file with the result?
“MOVIE1.mov” was only an example, the movie names have different length and might including spaces or various symbols (underscore, etc) .

the character [TAB] is the delimiter between the various movie names and the duration.
Regards
Dan

Hi,

try this, it assumes a file movies.txt on the desktop and creates a file newmovies.txt with the changed content


set currentDesktop to path to desktop as text
set moviesFile to currentDesktop & "movies.txt"
set newMoviesFile to currentDesktop & "newmovies.txt"

set theSource to paragraphs of (read file moviesFile)

set TID to text item delimiters
set newSource to {}
repeat with aLine in theSource
	set text item delimiters to (tab & space)
	set {prefix, duration} to text items of aLine
	set text item delimiters to ":"
	set {h, m, s, f} to text items of duration
	set frameCount to (h * hours + m * minutes + s) * 25 + f
	set end of newSource to prefix & tab & space & frameCount & " Frames"
	
end repeat
set text item delimiters to return
set newSource to newSource as text
set text item delimiters to TID

try
	set fileRef to open for access file newMoviesFile with write permission
	write newSource to fileRef
	close access fileRef
on error
	try
		close access file newMoviesFile
	end try
end try


Thanks Stefan, however i receive this error message:
error “Can’t get item 2 of {"MVI_9528.MOV 00:02:26:12"}.” number -1728 from item 2 of {“MVI_9528.MOV 00:02:26:12”}
i think it refers to

set {prefix, duration} to text items of aLine

can this be the reason for the error?

Regards

the script assumes that [TAB] is a real tab character (hex09) followed by a space

thanks again i fixed it …

set text item delimiters to tab

while in your original script was set text item delimiters to (tab and space)

also the script hanged finding a carriage return at the last paragraph: with TextWrangler i was able to create a new file without a final carriage return ant it worked. How to avoid this within the scrpt?

Maybe do you have a suggestion on my other question?
how to tell Quicktime player to start playing from the frame position?

Regards Dan

then you should also remove & space in this line


set end of newSource to prefix & tab & space & frameCount & " Frames"

regarding the trailing newline character I don’t understand the problem.
If the source text file does not have a trailing newline character the new created file doesn’t have one either.

To skip empty paragraphs check the length of the line


repeat with aLine in theSource
	if (length of aLine) > 0 then
		--.
	end if
end repeat

Thank you and Regards

This can be interpreted in various ways.

For instance, there’s “frame” as defined in the movie itself and there’s the standard definition of “frame” as a 25th of a second (which is apparently the same thing in your movies).

Then there’s the difference between frame number and time code position. Frame number 1 begins at time code position “00:00:00.0”. Time code “00:00:00.23” means that twenty-three frames have been completed and we’re somewhere in frame number 24. If you want to start at time code “00:00:00.23”, you have to start at frame number 24.

I haven’t scripted QuickTime Player for a while, but the easy solution, which may be good enough for you, looks to be something like this:

-- Going to a numbered frame as defined in the movie itself.

set frameNumber to 25 -- Start at the beginning of the 25th frame in the movie.

set movieFile to (choose file)
tell application "QuickTime Player 7"
	activate
	open movieFile
	
	tell document 1
		set current time to time of frame frameNumber of track 1
	end tell
end tell

Slightly less simple, but capable of going to a position given in standard frames, regardless of the movie’s actual frame rate:

-- Going to a time position given in frames at 25 frames/second.

set framePosition to 25 -- Start at end of frame 25 (ie. 1 second in).
-- set framePosition to framePosition - 1 -- Start at beginning of frame 25.

set movieFile to (choose file)
tell application "QuickTime Player 7"
	activate
	open movieFile
	
	tell document 1
		set {ds, dr, d} to {data size, data rate, duration} of track 1
		set current time to d / (ds / dr) / 25 * framePosition
	end tell
end tell

Thanks Nigel
both your script work perfectly, I want to explain what we are trying to achieve.
We are using FilemakerPro database as a pre-editing tool for a film we shoot
Too complex here to explain the reasons for this choice
The scripts in reply to the first question allows us to create a frame field in FMP to then choose various different starting points in our film-files.

We use successfully this FMP and Applescript combined script from within filemaker to open clips we choose from our FMP file:

Let (
mac_path = Right ( Substitute ( Media Path; “/”; “:”); Length (Media Path) - 1);

“tell application "Quicktime 7"” & ¶ &
“activate” & ¶ &
"open " & Quote ( mac_path ) & ¶ &
"
set the dimensions of movie 1 to {480, 270}
" & ¶ &
“end tell”
)

the script calls the clip in QT and plays it
we use the script to open more than one QT window to compare takes as QT allows to see more than one film at the time,

While boths cript you suggested work perfectly from within Filemaker as “Native Applescripts” playing from the starting point set in the script, I am not able to adapt parts of your scripts in the one we use already. we need to merge them to use some of the fields in my database for the framenumber required.

Adding this information to the original working script, Quicktime opens the film and gives an error telling it cannot set the playhead to the frame.

This is what I did

Let (
mac_path = Right ( Substitute ( Media Path; “/”; “:”); Length (Media Path) - 1);
"set framenumber to " & Frames & ¶ &
“tell application "Quicktime 7"” & ¶ &
“activate” & ¶ &
"open " & Quote ( mac_path ) & ¶ &
"set current time to framenumber " & ¶ &
“set the dimensions of movie 1 to {480, 270}” & ¶ &
“end tell”
)

Is there a way to fit parts of your scripts in FMP?

Regards

Dan

Hi danwan.

I’m afraid I don’t know anything about using FMP. But in the AppleScript code, you have to set the ‘current time’ of the movie document (eg. ‘current time of movie 1’ ” or ‘current time of document 1’ as it is now). Also, in QuickTime, time is measured in packets of data, not in frames. That’s why my scripts two posts up either read the time position from the relevant ‘frame’ in the movie itself (first script) or calculate it from other data (second script).

Thanks for your attention to my post.
I add the working script which reads a frame number from an FMP field opens Quicktime and begins playing the clip at the specified frame from the FMP database.
Perhaps it can be of some use to others.
Regards

Let (
mac_path = Right ( Substitute ( ClipsWork::Media Path; “/”; “:”); Length (ClipsWork::Media Path) - 1);
"set frame_number to " & ClipsWork::frames & ¶ &
“tell application "QuickTime Player 7"” & ¶ &
“activate” & ¶ &
"tell (open " & Quote ( mac_path ) & “)” & ¶ &
“set current time to frame_number / 25 * time scale” & ¶ &
“set dimensions to {480, 270}” & ¶ &
“end tell” & ¶ &
“end tell”
)