Search code examples
applescriptquicktime

Applescript trim movies in quicktime


I would like to trim a video file per frame number rather than seconds. So far I have tried a few options and this is the most successful one so far:

set start_trim to 5
set end_trim to 6

tell application "QuickTime Player"
    activate
    try
        set movieFile to (the POSIX path of ("PathToMovieFolder")) & "MyMovie.mov"
    on error errorMsg number errorNum
        display alert errorMsg & space & errorNum message ¬
            "An error occured trying to find the file " & movieFile & "." & return & ¬
            "Check the file path exists, and the file spelling." as warning giving up after 60
    end try
    try
        open movieFile with presenting
        delay (0.25)
        present document 1
        delay (0.25)
        trim document 1 from start_trim to end_trim
        display alert errorMsg & space & errorNum message ¬
            "An error occured trying to open & play the file " & movieFile & "." & return & ¬
            "Check the file path exists, and the set delay time" as warning giving up after 60
    end try
end tell

What it does is that it trims it to seconds rather than exact frames. Any ideas on how to solve this?


Solution

  • Frame is not in the QuickTime Player dictionary. However, it is in the QuickTime Player 7 dictionary. If you need to trim using frames rather than seconds, I would suggest finding a copy of QuickTime Player 7.

    or maybe you could do something like this:

    set FPS to 29.97
    set start_trim to 5
    set end_trim to 7
    
    set startFrame to start_trim / FPS
    set endFrame to end_trim / FPS
    
    tell application "QuickTime Player"
        activate
        trim document 1 from startFrame to endFrame
    end tell