Creating Movies

iMagine Photo has the ability to create movies and add frames to that movie. Adding frames to a movie is very much like exporting an image from a graphic or window document to a new file. The frame is a snaphsot of the graphic document at the requested time. All the image drawing, shape drawing, applying of filters to the graphic document is captured by the snapshot. iMagine Photo has no functionality for adding sounds tracks to the movies that it creates.

Movie creation is done through a movie editor object. The following line of script creates a movie editor object.

set movieEditor to make new movie editor with properties {dimensions:{320, 264}}

A movie editor includes most of the functionality of a movie importer, except that it cannot be created from importing a movie file. A movie editor cannot open a movie file so that the movie importer commands apply to the frames created in the current session only. Drawing frames from a movie importer should not be done while the movie editor is in editing mode.

Before adding frames it is necessary to have the movie editor in editing mode, the following line of code does this:

set editing of movieEditor to true

But before you set the editing state of the movie editor to true you should set the data compressor to the video codec that you want to compress your frames with. The default codec is "Apple Animation" so setting the data compressor is not required but you probably want to decide which codec you want to use. The following command will get a list of available video codecs installed on your Macintosh.

set compressorTypes to compressor types

The following script obtains a list of compressor types, creates a temporary movie editor and sets the data compressor to each one of the compressor types in turn and requests information about each data compressor from the movie editor. The returned information is displayed in the results panel of the Script Editor window. Panther users can open the following script in a new Script Editor window by clicking here.

on run
  
tell application "iMagine Photo"
    
set compressorTypes to compressor types
    
set movieEditor to make new movie editor with properties {dimensions:{320, 240}}
    
set theList to {}
    
repeat with theType in compressorTypes
      
set the data compressor of movieEditor to theType
      
set theProps to the properties of movieEditor
      
copy theProps to the end of theList
    
end repeat
    
close movieEditor
  
end tell
  
theList
end run

The information returned like compress1Bit indicates whether the compressor type can comress to that bit depth or not. For those who look closely you will notice that data compressor "Sorenson Video 3 Compressor" claims not to able to compress at any of advertised bit depths. I don't understand enough about Video Codecs about what is actually happening here, but the "Sorenson Video 3 Compressor" appears to give the best results for mosts of the runs I have done which involve images from digitial cameras in terms of small file size and image quality.

Once you have specified the data compressor you can set the bit depth for data compression to any bit depth that the compressor can handle, or you can leave the bit depth unchanged.

The following script reduces the frame width to 3/4 of the original movie and makes the frame height 4/3 of the original. It also adds a small amount of text at the bottom right of every frame of the movie. The script allows you to choose the data compressor to compress the frames with and asks where you want to save the movie. The resulting movie has one frame for each frame of the original movie at exactly the same times as the original. The frame rate does not have to be constant. This is achieved by requesting from the original movie when the next frame will draw. In this case the only frame where the length of the frame is unknown is the last frame. As for most of the scripts in the documentation a window document is created so that there is some visual feedback when running the script. This affects performance and in any sort of production use all processing would be done offscreen in a graphics document. Panther users can open the following script in a new Script Editor window by clicking here.

on run
  
set movieFile to choose file with prompt "Choose movie file to copy: " without invisibles
  
set newFileLocation to choose file name with prompt "Save tall movie to: " default name "tallMovie.mov"
  
set drawingText to text returned of (display dialog "Enter the text to add to the bottom of the movie: " default answer "www.yvs.eu.com")
  
tell application "iMagine Photo"
    
launch
    
set movieImporter to import movie movieFile
    
if the component error of movieImporter is not equal to 0 then
      
display dialog "The file is not a movie Quicktime recognizes"
      
close movieImporter
      
return
    
end if
    
set timeScaleScale to 600 / (time scale of movieImporter)
    
set maximum samples of movieImporter to -1
    
set {x, y, width, height} to natural bounds of movieImporter
    --
the new movie is twice as tall as the old.
    
set newMovieWidth to (width * 3) div 4
    
set newMovieHeight to (height * 4) div 3
    
set movieEditor to make new movie editor with properties {dimensions:{newMovieWidth, newMovieHeight}}
    
set dataCompressors to the compressor types
    
set theCompressor to choose from list dataCompressors with prompt "Choose the data compressor to compress your data with"
    
set the data compressor of movieEditor to theCompressor
    
set thisDocument to make new window document with properties {dimensions:{newMovieWidth, newMovieHeight}}
    
set the drawing destination of movieImporter to thisDocument
    
set the destination rectangle of movieImporter to {0, 0, newMovieWidth, newMovieHeight}
    
set the export file location of movieEditor to newFileLocation
    
set theSamples to the drawing samples of movieImporter
    --
if you want to change the compression quality setting then replace
    --
high, with one of minimum, low, medium, high, maximum, lossless
    
set the export compression quality of movieEditor to high
    
set editing of movieEditor to true
    
repeat with i from 1 to the (count of theSamples) - 1
      
set the current time of movieImporter to item i of theSamples
      
set theDuration to (((item (i + 1) of theSamples) - (item i of theSamples)) * timeScaleScale) as integer
      
draw movieImporter
      
tell thisDocument to create composition element with properties {class:standard text, font:"Monaco", font size:9, start point:{newMovieWidth, newMovieHeight}, start from:bottom right, color:{65535, 65535, 65535}, background color:{0, 0, 0}, drawing text:drawingText}
      
tell movieEditor to append sample with properties {source document:thisDocument, source rectangle:{0, 0, width, 2 * height}, sample duration:theDuration}
    
end repeat
    --
all the samples have been done except the last, do that now.
    
set the current time of movieImporter to last item of theSamples
    
draw movieImporter
    
tell thisDocument to create composition element with properties {class:standard text, font:"Monaco", font size:9, start point:{newMovieWidth, newMovieHeight}, start from:bottom right, color:{65535, 65535, 65535}, background color:{0, 0, 0}, drawing text:drawingText}
    
tell movieEditor to append sample with properties {source document:thisDocument, source rectangle:{0, 0, width, 2 * height}, sample duration:theDuration}
    
set editing of movieEditor to false
    display dialog "About to export movie: " giving up after 10
    
export movieEditor
    
close movieEditor
    
close movieImporter
    
close thisDocument
  
end tell
end run

The ability to open scripts in a new Script Editor window is provided by an application called "Convert Script to Markup Code" and can be obtained from http://homepage.mac.com/jonn8/as/

keywords: AppleScript, Apple Script, shape drawing, Macintosh, Quicktime, Movies