User Tools

Site Tools


software:mov2flv

This is an old revision of the document!


mov2flv conversion script

This applescript below converts quicktime .mov files to .flv files.

prerequisites

  • Create in After Effects a render profile called “Adobe Flash Video”, which uses the on6 codec for video and mp3 (256 kb/s) for audio.

Usage

  • drag and drop one or more files or a folder onto this script.

Code

-- 
-- ae_mov2flv.app
-- 
-- an apple script applet to convert .mov files to .flv files
-- this is specially for users which want to record clips with the macbook with an external microphone
--and correct (small) offset between audio and video
-- It uses Adobe After Effects CS3 to convert, correct audio offset and render into flv with on6/mp3 codec
--

-- Applet Code
-- 
-- The following appears only when the droplet is double clicked
on run
    display dialog "ae_mov2flv.app" & return & return & "Convert a mov w/Audio to a flv file" & return & return & "To convert .mov files to .flv, just drag the files or folders of files onto this applet.  The script will start Adobe After Effects CS3, setup a composition, correct offset between audio video." & return & return & "The resulting converted .flv movie files will be in the same folder."
end run

-- This droplet processes both files or folders of files dropped onto the applet
on open (these_items)
    repeat with i from 1 to the count of these_items
        set this_item to (item i of these_items)
        set the item_info to info for this_item
        if folder of the item_info is true then
            process_folder(this_item)
        else if (alias of the item_info is false) and (the name extension of the item_info is "MOV") then
            process_item(this_item)
        end if
    end repeat
    
    --    display dialog "Converted the movie(s)." & return & return & "Enjoy!"
end open

-- this sub-routine processes folders
on process_folder(this_folder)
    set these_items to list folder this_folder without invisibles
    repeat with i from 1 to the count of these_items
        set this_item to alias ((this_folder as text) & (item i of these_items))
        set the item_info to info for this_item
        if folder of the item_info is true then
            process_folder(this_item)
        else if (alias of the item_info is false) and (the name extension of the item_info is "MOV") then
            process_item(this_item)
        end if
    end repeat
end process_folder

-- this sub-routine processes files
on process_item(this_item)
    -- NOTE that the variable this_item is a file reference in alias format
    set full_path to the POSIX path of this_item
    -- !!! MODIFY THESE PARAMETERS TO SUIT if you have other preferences you'd like to use
    -- activate AE (this will be ignored if it's already open)
    try
        tell application "Adobe After Effects CS3"
            with timeout of 300 seconds
                activate
                
                -- begin After Effects script: close any open project (if it isn't rendering)
                set line1 to "if (app.project.renderQueue.rendering != true){" & return
                set line2 to "app.project.close(CloseOptions.DO_NOT_SAVE_CHANGES);}" & return
                set closeAnyExistingProjects to line1 & line2
                DoScript closeAnyExistingProjects with override
                -- end After Effects script
                
                -- begin After Effects script
                set line1 to "if(!app.project){" & return
                set line2 to "var myProject = app.newProject();}" & return
                set line3 to "else{" & return
                set line4 to "var myProject = app.project;}" & return
                set line5 to "var theFile = \"" & this_item & "\";" & return
                set line6 to "var outFile = theFile.substring(0, theFile.lastIndexOf(\".\"));" & return
                set line7 to "var c=0;" & return
                set line8 to "var cs=\"\";" & return
                set line9 to "do{"
                set line10 to "if (c > 0) {cs = \"(\" + c.toString() + \")\"};" & return
                set line11 to "c=c+1;" & return
                set line12 to "} while (File(outFile + cs + \".flv\").exists)" & return
                set line13 to "var importOptions = new ImportOptions (new File (theFile));" & return
                set line14 to "if(importOptions.canImportAs(ImportAsType.FOOTAGE)){" & return
                set line15 to "try{"
                set line16 to "var myItem = myProject.importFile(importOptions);" & return
                set line17 to "var newComp = myProject.items.addComp(\"rendercomp\",myItem.width,myItem.height,myItem.pixelAspect,myItem.duration, myItem.frameRate);" & return
                set line18 to "var VideoLayer = newComp.layers.add(myItem);" & return
                set line19 to "var AudioLayer = newComp.layers.add(myItem);" & return
                set line20 to "AudioLayer.audioEnabled = false;" & return
                set line21 to "VideoLayer.enabled = false;" & return
                set line22 to "AudioLayer.startTime = AudioLayer.startTime - 3*(1/myItem.frameRate);" & return
                set line23 to "var rendQueue = myProject.renderQueue.items.add(newComp);" & return
                set line24 to "var thisQueue = myProject.renderQueue.item(myProject.renderQueue.numItems);" & return
                set line25 to "thisQueue.outputModules[1].applyTemplate(\"Adobe Flash Video\");" & return
                set line26 to "thisQueue.outputModule(1).file = new File(outFile+cs+\".flv\");" & return
                set line27 to "thisQueue.applyTemplate(\"Best Settings\");" & return
                set line28 to "myProject.renderQueue.render();" & return
                set line29 to "newComp.remove();" & return
                set line30 to "myItem.remove();" & return
                set line31 to "}catch(e){" & return
                set line32 to "}" & return
                set line33 to "}" & return
                set mov2flv to line1 & line2 & line3 & line4 & line5 & line6 & line7 & line8 & line9 & line10 & line11 & line12 & line13 & line14 & line15 & line16 & line17 & line18 & line19 & line20 & line21 & line22 & line23 & line24 & line25 & line26 & line27 & line28 & line29 & line30 & line31 & line32 & line33
                DoScript mov2flv
                -- end After Effects script
                
            end timeout
            
            -- begin After Effects script: quit application
            set line1 to "myProject.close(CloseOptions.DO_NOT_SAVE_CHANGES);" & return
            set line2 to "app.quit();" & return
            DoScript line1 & line2 with override
            -- end After Effects script
            
            delay 5
            
        end tell
    on error the error_message number the error_number
        display dialog "Error: " & the error_number & ". " & the error_message
    end try
end process_item


on getFileName(thefile)
    set {oldDelims, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {":"}}
    set mytextfilename to last text item of (thefile as text)
    set AppleScript's text item delimiters to oldDelims
    return mytextfilename
end getFileName
software/mov2flv.1286678457.txt.gz · Last modified: 2010/10/10 04:40 (external edit)