• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: QuickTime Time from SMPTE Time
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: QuickTime Time from SMPTE Time


  • Subject: Re: QuickTime Time from SMPTE Time
  • From: Brennan Young <email@hidden>
  • Date: Thu, 23 Aug 2001 23:44:19 +0200
  • Organization: Magic Lantern

Emmanuel <email@hidden> wrote

> At 19:37 +0200 22/08/01, Judi Smith wrote:
>
> >I am trying to write a script that makes a selection in the QT Player of a
> >section of a movie. I have SMPTE time code, but that doesn't seem to
> >correspond to the time that QT Player is expecting. Can somebody tell me
> >where to find the time scale or base that QT is using?
>
> I don't know what SMPTE is, so I suppose I am missing something, but just
> in case. QuickTime Player gives the "duration", the "current time" and the
> "time scale": what can be missing here? "duration"/"time scale" = the
> duration in seconds.

Close, but no cigar. The time scale refers to how each second is subdivided.
Commonly this will be 24 (film), 25 (pal), 30 (NTSC) or some lower value
such as 12 or 15 for content created and distributed entirely digitally. In
a SMPTE context (look up the acronym) The Quicktime 'standard' time scale is
600, because it divides exactly by all the aforementioned common time scales,
although Quicktime can go all the way up to 1000, maybe even further.

Anyway, to convert timecodes of the form "00:02:43.09" i.e. Hours:Minutes:Seconds:timescale,
you'll need to know the timescale you are working with, for example 30 if it is NTSC.
After that it's basic maths.

The hard part is parsing the timecodes.
I thought I could use applescript's text item delimiters but they seem only to be used when converting
from lists to strings, not the other way round.

Here's a script which will do some of the job then. It just moves the playback head, but with a bit of
modification, you could get it to make selections instead.

There's quite a bit of error checking,
but I wouldn't claim it to be foolproof.

property mostRecentTimecode : "00:02:43.09"
property mostRecentTimebase : "30"

on run
tell application "QuickTime Player"
if movie 1 exists then
tell movie 1
set QTtime_scale to time scale
end tell
else
set prmpt to "No movies open."
display dialog prmpt buttons {"Rats"} default button 1
end if
end tell
set prmpt to "Enter timecode. (Time base " & mostRecentTimebase & ")"
set b to {"Cancel", "Change timebase...", "OK"}
set d to (display dialog prmpt buttons b default answer mostRecentTimecode default button 3)
set newTimeCode to the text returned of d
set br to the button returned of d

if br is "Change timebase..." then
set prmpt to "Enter new timebase"
set d to (display dialog prmpt default answer mostRecentTimebase)
set newTimebase to (the text returned of d) as integer
set mostRecentTimebase to (newTimebase as string)
end if

set QTmovietime to SMPTEtoQuicktime(newTimeCode, mostRecentTimebase, QTtime_scale)
if QTmovietime = -1 then -- error

else
tell application "QuickTime Player"
set current time of movie 1 to QTmovietime
end tell
set mostRecentTimecode to newTimeCode
end if
--SMPTEtoQuicktime("00:02:43.09", 30)
QTmovietime
end run

on SMPTEtoQuicktime(timeStamp, time_scale, QTtime_scale)
-- convert timecode string to {hh, mm, ss, tc}
set timeCodes to parseTimeCode(timeStamp)
if timeCodes is {} then
return -1 -- this is an error code
end if
set {hh, mm, ss, tc} to timeCodes
-- synchronise timebases
set adjustedtime_scale to QTtime_scale / time_scale
set oneMinute to QTtime_scale * 60
set oneHour to oneMinute * 60

set t to ((tc * adjustedtime_scale) as integer)
set s to ss * QTtime_scale
set m to (mm * oneMinute)
set h to (hh * oneHour)
return h + m + s + t
end SMPTEtoQuicktime

-- returns list of integers in the form {hh, mm, ss, tc}, or {} if there is an error
on parseTimeCode(timeStamp)

set timeStamp to timeStamp & "."
set timeUnits to {}
set thisUnitString to ""
set thisUnitValue to 0
set wellFormed to true

repeat with ch in timeStamp

set ch to (ch as string)

if ch is in "0123456789" then -- numerical character

set thisUnitString to (thisUnitString & ch) -- keep building the string

else if ch is "." or ch is ":" then -- timecode delimter

try -- to convert what we have so far
set thisUnitValue to (thisUnitString as integer)
on error msg number n
if n = -1700 then -- can't make string into number
set wellFormed to false
end if
end try

set timeUnits to timeUnits & thisUnitValue
set thisUnitString to "" -- start a new string

else -- some other character we didn't expect
set prmpt to "Unexpected character: \"" & ch & "\""
display dialog prmpt buttons {"Rats"} default button 1
set wellFormed to false
end if

end repeat

if wellFormed then
return timeUnits
else -- make a nice error message
beep
set prmpt to "Badly formed timecode!" & return
set prmpt to prmpt & "Expected \"HH:MM:SS:ttt\" or \"HH:MM:SS:tt\" but got "
set prmpt to prmpt & return & "\"" & timeStamp & "\""
display dialog prmpt buttons {"Rats"} default button 1
return {}
end if

end parseTimeCode


--
_____________

Brennan


  • Prev by Date: Re: Microsoft Outlook for Exchange Mac Version
  • Next by Date: Applescript & Tex-Edit Plus
  • Previous by thread: Re: QuickTime Time from SMPTE Time
  • Next by thread: Re: QuickTime Time from SMPTE Time
  • Index(es):
    • Date
    • Thread