Applescript to split dv stream files into chunks that iMovie can import

Laine Lee llee at txdirect.net
Tue Apr 22 12:14:04 PDT 2003


Here's a script you can use to split dv stream movie files into chunks with
QuickTime Player Pro to work around the iMovie file size limit. It's good
for bringing any appropriate Quicktime movie into iMovie or even just to
"recycle" an iMovie 3 output movie. Save it as a application with the Script
Editor. You'll be prompted for a folder for saving the movie output. After
you save the script as an application, just drop your movie onto the
resulting droplet. If you want to change the default folder for saving, just
open the droplet in the script editor again. Tested in OS X 10.2.

------

property mydestination : choose folder with prompt ¬
    "Choose a destination folder for the segments."

on open sourcefile
    set this_time to 1
    --set sourcefile to choose file with prompt ¬
    "Choose a movie file you want split into segments."
    
    tell application "QuickTime Player"
        activate
        stop every movie
        try
            if exists movie 1 then close movie 1
            
            -- CHECK FOR THE CORRECT VERSION OF QUICKTIME
            set the QT_version to (the QuickTime version as string)
            set the player_version to (the version as string)
            set the required_version to "5.0.2"
            if (the QT_version is less than the required_version) or ¬
                (the player_version is less than the required_version) then
                set the error_message to ¬
                    "This script requires QuickTime " & ¬
                    the required_version & "  or greater." & ¬
                    return & return & ¬
                    "Current QuickTime Version: " & QT_version & return & ¬
                    "Current QuickTime Player Version: " & player_version
                my upgrade_QT(error_message)
            end if
            
            -- CHECK FOR QUICKTIME PRO
            if QuickTime Pro installed is false then
                set the error_message to "This script requires a
            QuickTime Pro installation on this system."
                my upgrade_QT(error_message)
            end if
            
            set myfile to open sourcefile
            
        on error error_message number error_number
            if the error_number is not -128 then
                beep
                display dialog error_message buttons {"Cancel"} default
button 1
            end if
        end try
        
        --if not (exists movie 1) then error "No movies are open."
        
    end tell
    repeat
        activate
        display dialog ¬
            "Enter the number of seconds for segments.
            560 should make them less than 2 G in size." default answer ¬
            "560" buttons {"Cancel", "Set Segment Length"} default button 2
        copy the result as list to {segment_length_in_seconds, go_ahead}
        try
            if the segment_length_in_seconds is not "" then
                set the segment_length_in_seconds to the ¬
                    segment_length_in_seconds as number
                exit repeat
            end if
        end try
    end repeat
    
    
    repeat
        try
            tell application "QuickTime Player"
                
                tell movie 1
                    set the selection end to (the selection start + ¬
                        (segment_length_in_seconds * time scale))
                end tell
                if (data size of movie 1) > 0 then
                    set start_name to name of movie 1
                    cut movie 1
                    make new movie
                    paste movie 1
                   
                    set mynewfile to ((mydestination as string) & ¬
                        start_name & "_" & this_time)
                    with timeout of 3600 seconds
                        export movie 1 to file (mynewfile & ".dv") ¬
                            as DV stream using most recent settings
                    end timeout
                    close movie 1 without saving
                else
                    error number -128
                end if
            end tell
            set this_time to (this_time + 1)
        on error
            tell application "QuickTime Player"
                activate
                if (data size of movie 1) > 0 then
                    with timeout of 3600 seconds
                        export movie 1 to file (((mydestination as string) &
this_time) & ".dv") ¬
                            as DV stream using most recent settings
                    end timeout
                    close movie 1 without saving
                else
                    close movie 1 without saving
                end if
            end tell
            exit repeat
        end try
    end repeat
end open

on upgrade_QT(passed_message)
    tell application "QuickTime Player"
        activate
        stop every movie
        set the target_URL to "http://www.apple.com/quicktime/download/"
        display dialog passed_message & return & return & ¬
            "If this computer is currently connected to the Internet, " & ¬
            "click the ?pgrade?button to visit the QuickTime Website."
buttons ¬
            {"Upgrade", "Cancel"} default button 2
        ignoring application responses
            tell application "Finder"
                open location target_URL
            end tell
        end ignoring
        error number -128
    end tell
end upgrade_QT


--------

-- 
Laine Lee
llee at lonestar.utsa.edu
http://lonestar.utsa.edu/llee



More information about the MacDV mailing list