I need help making a CMTime variable in swift 2 so I can create a AVMutableCompostion. Current code:
let videoAsset: AnyObject! = AVAsset(URL: outputFileURL)
let videoDuration:CMTime = CMTimeMake(Int64(videoAsset.duration), 1)
but the variable videoDuration above keeps returning nil! I double checked to make sure the videoAsset.duration was not nil and it is not.
Abstract: leads it to crash here at the line where "videoDuration" is passed in as a peramiter
// Merge audio and video tracks to complete video
let videoTrack = mixComposition.addMutableTrackWithMediaType(AVMediaTypeVideo, preferredTrackID: Int32(kCMPersistentTrackID_Invalid))
do {
try videoTrack.insertTimeRange(CMTimeRangeMake(kCMTimeZero, videoDuration),
ofTrack: videoAsset.tracksWithMediaType(AVMediaTypeVideo)[0] ,
atTime: kCMTimeZero)
} catch _ {
/* TODO: Finish migration: handle the expression passed to error arg: kCMTimeZero */
}
Please help! Any suggestions would be greatly appreciated :)