Saturday, April 10, 2010

Automated Export/Import in FCP (Baking) Version 0.95

Introduction:

With Color 1.5 the compatibility with transitions and speedchanges got better, but sometimes you still have to render some clips before you can send a timeline from Final Cut to Color without getting any errors. And if you are still working with Color 1.0 (like I do) you need this anyway.
There will be newer versions of this script. If you need it a bit different, drop me a line and I'll add or remove functions.

What this Script does:
Exports clips from FCPs timeline and imports them to same location (called "baking" clips).

What you need:
OS X, Final Cut Pro, AppleScript Editor,
Keyboard Maestro to assign a Keyboard Shortcut to trigger the script. Unfortunately the script does not work through the script menu or as a service :(

Preparations:

See Mini How To's to
  • Create Applescript with following code and save to the standard script folder.

Baking Script 0.95 (24.05.2010)

- Now possible to trigger the script without Keyboard Maestro, or any other additional software.


activate

set PropertyList to {"Bake video only", "Bake with audio"} -- create a list for different settings


set the ChosenItem to choose from list PropertyList default items {item 1 of PropertyList}

set ChosenItem to ChosenItem as string


if ChosenItem is "Bake video only" then

-- textfiles that store name and path information

set ClipnameHelper to (path to home folder as string) & "Library:Application Support:DIYStudio:HelperFiles:Clipname.txt" as string

set CounterHelper to (path to home folder as string) & "Library:Application Support:DIYStudio:HelperFiles:Counter.txt" as string

set pathhelper to (path to home folder as string) & "Library:Application Support:DIYStudio:HelperFiles:Complete.txt" as string

set PathToClipFolder to (POSIX path of (choose folder))

try

set pathhelperReference to open for access pathhelper with write permission

on error

tell application "Finder" -- if you run the script for the first time it will create the text files that help storing last used names and counter

make new folder at (path to home folder as string) & "Library:Application Support:" with properties {name:"DIYStudio"}

make new folder at (path to home folder as string) & "Library:Application Support:DIYStudio:" with properties {name:"HelperFiles"}

set pathhelperReference to open for access pathhelper with write permission

end tell

end try

set eof of pathhelperReference to 0

write (PathToClipFolder as string) to pathhelperReference starting at eof

set shortPathToClipFolder to read pathhelperReference from 1

close access pathhelperReference

set ClipnameHelperReference to open for access ClipnameHelper with write permission

try

set ClipnameHelperContents to read ClipnameHelperReference as string from 1

on error

write "Baked" to ClipnameHelperReference starting at eof

set ClipnameHelperContents to read ClipnameHelperReference as string from 1

end try

set eof of ClipnameHelperReference to 0

set Clipname to text returned of (display dialog "Enter clipname:" default answer ClipnameHelperContents)

write Clipname to ClipnameHelperReference starting at eof

close access ClipnameHelperReference

set CounterHelperReference to open for access CounterHelper with write permission

try

set CounterHelperContents to read CounterHelperReference

on error

write "0" to CounterHelperReference starting at eof

set CounterHelperContents to read CounterHelperReference as string from 1

end try

set counter to CounterHelperContents + 1

set eof of CounterHelperReference to 0

write counter as string to CounterHelperReference starting at eof

close access CounterHelperReference

set combinedClipname to Clipname & " " & (counter as string)

tell application "Final Cut Pro" to activate

-- this section runs the actual activity. You can copy everything and then adjust the following to get different settings. E.g. if you want to render audio and video, you could delete the tab and arrow keys. Or if you want to use a different codec, remove only one tab and add down arrow to choose the setting

tell application "System Events" to keystroke "i" using command down & shift down

delay 0.5

tell application "System Events" to keystroke "e" using command down

delay 0.5

tell application "System Events" to keystroke "g" using command down & shift down

delay 0.5

tell application "Finder" to set the clipboard to shortPathToClipFolder as string

delay 0.5

tell application "System Events" to keystroke "v" using command down

delay 0.5

tell application "System Events" to keystroke return

delay 0.5

tell application "Finder" to set the clipboard to combinedClipname

delay 1

tell application "System Events" to keystroke "v" using command down

delay 1

tell application "System Events" to keystroke tab

tell application "System Events" to keystroke tab

tell application "System Events" to keystroke tab

tell application "System Events" to keystroke tab

tell application "System Events" to keystroke tab

tell application "System Events" to keystroke tab

tell application "System Events" to keystroke tab

tell application "System Events" to keystroke tab

tell application "System Events" to key code 125 -- down arrow

tell application "System Events" to key code 125

tell application "System Events" to key code 125

tell application "System Events" to keystroke return

tell application "System Events" to keystroke return

set myFile to (PathToClipFolder & combinedClipname & ".mov")

delay 1

-- compares the filesize of the new clip over time. As long s it increases it means that it's still rendering

set Size_1 to size of (info for myFile) -- get initial size

delay 2

set Size_2 to size of (info for myFile)

repeat while Size_2Size_1 --if they don't equal, loop until they do

set Size_1 to size of (info for myFile) -- get initial size

delay 1

set Size_2 to size of (info for myFile)

end repeat

-- importing...

tell application "System Events" to keystroke "i" using command down

delay 1

tell application "System Events" to keystroke "g" using command down & shift down

tell application "Finder" to set the clipboard to myFile as string

delay 0.5

tell application "System Events" to keystroke "v" using command down

tell application "System Events" to keystroke return

tell application "System Events" to keystroke return

delay 0.5

tell application "System Events" to key code 21 using command down

delay 0.5

tell application "System Events" to keystroke return

delay 0.5

tell application "System Events" to key code 109 -- F10 key

else if ChosenItem is "Bake with audio" then

-- textfiles that store name and path information

set ClipnameHelper to (path to home folder as string) & "Library:Application Support:DIYStudio:HelperFiles:Clipname.txt" as string

set CounterHelper to (path to home folder as string) & "Library:Application Support:DIYStudio:HelperFiles:Counter.txt" as string

set pathhelper to (path to home folder as string) & "Library:Application Support:DIYStudio:HelperFiles:Complete.txt" as string

set PathToClipFolder to (POSIX path of (choose folder))

try

set pathhelperReference to open for access pathhelper with write permission

on error

tell application "Finder" -- if you run the script for the first time it will create the text files that help storing last used names and counter

make new folder at (path to home folder as string) & "Library:Application Support:" with properties {name:"DIYStudio"}

make new folder at (path to home folder as string) & "Library:Application Support:DIYStudio:" with properties {name:"HelperFiles"}

set pathhelperReference to open for access pathhelper with write permission

end tell

end try

set eof of pathhelperReference to 0

write (PathToClipFolder as string) to pathhelperReference starting at eof

set shortPathToClipFolder to read pathhelperReference from 1

close access pathhelperReference

set ClipnameHelperReference to open for access ClipnameHelper with write permission

try

set ClipnameHelperContents to read ClipnameHelperReference as string from 1

on error

write "Baked" to ClipnameHelperReference starting at eof

set ClipnameHelperContents to read ClipnameHelperReference as string from 1

end try

set eof of ClipnameHelperReference to 0

set Clipname to text returned of (display dialog "Enter clipname:" default answer ClipnameHelperContents)

write Clipname to ClipnameHelperReference starting at eof

close access ClipnameHelperReference

set CounterHelperReference to open for access CounterHelper with write permission

try

set CounterHelperContents to read CounterHelperReference

on error

write "0" to CounterHelperReference starting at eof

set CounterHelperContents to read CounterHelperReference as string from 1

end try

set counter to CounterHelperContents + 1

set eof of CounterHelperReference to 0

write counter as string to CounterHelperReference starting at eof

close access CounterHelperReference

set combinedClipname to Clipname & " " & (counter as string)

tell application "Final Cut Pro" to activate

-- this section runs the actual activities in FCP.

tell application "System Events" to keystroke "e" using command down

delay 0.5

tell application "System Events" to keystroke "g" using command down & shift down

delay 0.5

tell application "Finder" to set the clipboard to shortPathToClipFolder as string

delay 0.5

tell application "System Events" to keystroke "v" using command down

delay 0.5

tell application "System Events" to keystroke return

delay 0.5

tell application "Finder" to set the clipboard to combinedClipname

delay 1

tell application "System Events" to keystroke "v" using command down

tell application "System Events" to keystroke return

set myFile to (PathToClipFolder & combinedClipname & ".mov")

-- compares the filesize of the new clip over time. As long s it increases it means that it's still rendering

delay 1

set Size_1 to size of (info for myFile) -- get initial size

delay 2

set Size_2 to size of (info for myFile)

repeat while Size_2Size_1 --if they don't equal, loop until they do

set Size_1 to size of (info for myFile) -- get initial size

delay 1

set Size_2 to size of (info for myFile)

end repeat

-- importing...

tell application "System Events" to keystroke "i" using command down

delay 1

tell application "System Events" to keystroke "g" using command down & shift down

tell application "Finder" to set the clipboard to myFile as string

delay 0.5

tell application "System Events" to keystroke "v" using command down

tell application "System Events" to keystroke return

tell application "System Events" to keystroke return

delay 0.5

tell application "System Events" to key code 21 using command down

delay 0.5

tell application "System Events" to keystroke return

delay 0.5

tell application "System Events" to key code 109 -- F10 key

end if

  • Create a shortcut with Keyboard Maestro to trigger the script.
Then
  • If you haven't already done so, set up a shortcut for exporting Quicktime movies in Final Cut. The script is made to use command + e. If you want to use a different shortcut, you have to change the script accordingly.

  • Dissable all but one videotrack.
  • Mark in and out points for the region you want to bake and replace.
Running the script:
  • Hit your shortcut
  • Choose an option from the list (if you made one)
  • Enter a name for the Clip(s)
  • Choose where to save them
  • Hit OK and wait until everything is done
I will also post a video soon. I figured video tutorials are just so much better, even if I sound like I'm falling asleep :D
So check back soon!

No comments:

Post a Comment