              #videoComposition: AVMutableVideoComposition,
                   #composition: AVMutableComposition) -> AVAssetExportSession {
     let session = AVAssetExportSession(asset: composition, presetName: preset)
-    session.videoComposition = videoComposition
+    session.videoComposition = videoComposition.copy() as AVVideoComposition
     // session.outputFileType = "com.apple.m4v-video"
-    session.outputFileType = AVFileTypeAppleM4V
+    // session.outputFileType = AVFileTypeAppleM4V
+    session.outputFileType = AVFileTypeQuickTimeMovie
     return session
 }
 


// Make movie assets from the URLs.
let movieAssets:[AVURLAsset] = urls.map { AVURLAsset(URL:$0, options:.None)! }

// Cursor time represents the time we are currently at in the movie.
var cursorTime = kCMTimeZero

// Create the mutable composition that we are going to build up.
var composition = AVMutableComposition()

import Cocoa
import AVFoundation

// Set the transition duration time to two seconds.
let transDuration = CMTimeMake(2, 1)

// The movies below have the same dimensions as the movie I want to generate
let movieSize = CGSizeMake(576, 360)

// This is the preset applied to the AVAssetExportSession.
// If the passthrough preset is used then the created movie file has two video
// tracks but the transitions between the segments in each track are lost.
// Other presets will generate a file with a single video track with the 
// transitions applied before export happens.
// let exportPreset = AVAssetExportPresetPassthrough
let exportPreset = AVAssetExportPreset640x480

// Path and file name to where the generated movie file will be created.
// If a previous file was at this location it will be deleted before the new
// file is generated. BEWARE
let exportFilePath:NSString = "~/Desktop/TransitionsMovie.mov"

// Create the list of paths to movie files that generated movie will transition between.
// The movies need to not have any copy protection.

let movieFilePaths = [
    "~/Movies/clips/410_clip1.mov",
    "~/Movies/clips/410_clip2.mov",
    "~/Movies/clips/410_clip3.mov",
    "~/Movies/clips/410_clip4.mov",
    "~/Movies/clips/410_clip5.mov",
    "~/Movies/clips/410_clip6.mov"
]

// Convert the file paths into URLS after expanding any tildes in the path
