如何使用AppleScript将帧中的QuickTime持续时间转换为时间格式?

时间:2014-08-14 16:13:09

标签: applescript quicktime duration

我对AppleScript相对较新。我试图将QuickTime持续时间转换为mm:ss时间格式,该格式舍入到最接近的秒。目前,它出现在我希望转换为秒的分钟和小数位。

我非常感谢任何建议。

到目前为止,我所拥有的......

set these_items to choose file with prompt "Select source file(s)" with multiple selections allowed
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) / (time scale of contents of q)) / 60
            display dialog "Movie duration of " & name of q & " = " & MovieDuration
        end try
    end tell
end repeat

2 个答案:

答案 0 :(得分:0)

我想我已经弄明白了。无论如何,这似乎给了我想要的结果:

set these_items to choose file with prompt "Select source file(s)" with multiple selections allowed
repeat with oneItem in these_items
    tell application "System Events"
        try
            set q to QuickTime file (oneItem as text)
            set MovieSeconds to (((duration of contents of q) / (time scale of contents of q)) mod 60) as string
            set x to text 1 thru ((offset of "." in MovieSeconds) - 1) of MovieSeconds
            set MovieSeconds to text -2 thru -1 of ("00" & x)
            set MovieMinutes to ((duration of contents of q) / (time scale of contents of q)) div 60
            display dialog "Movie duration of " & name of q & " = " & MovieMinutes & ":" & MovieSeconds
        end try
    end tell
end repeat

答案 1 :(得分:0)

获取时间戳持续时间的另一种方法是给电影一个午夜时间的日期,然后将持续时间秒添加到它,然后询问该日期的“时间字符串”。时间字符串格式为HH:MM:SS。

此示例适用于Mavericks上的QuickTime Player 10.3:

tell application "QuickTime Player"
    activate
    open (choose file with prompt "Choose a movie file:")
    set theMovie to a reference to the front document
    set theMovieDurationSeconds to the duration of theMovie
    set theMovieDate to date "Saturday, January 1, 2000 at 00:00:00"
    set theMovieDate to theMovieDate + theMovieDurationSeconds
    set theMovieDurationTimeString to the time string of theMovieDate
    display dialog "The movie duration:" & space & theMovieDurationTimeString buttons {"Cancel", "OK"} default button "OK" with title (the name as text) with icon note giving up after 60
end tell

对于持续时间为500秒的电影,时间字符串为“00:08:20”。

这种方法的优点是你不需要做任何数学运算,它应该适用于持续时间长达23:59:59的电影。

另请注意,您可以向QuickTime Player询问电影的持续时间。