Here is my code:
startTime = endTime
endTime = CMTimeMake(startTime.value + chunkSize, duration!.timescale)
if endTime > duration {
endTime = duration!
}
let composition = AVMutableComposition()
let videoCompTrack = composition.addMutableTrackWithMediaType(AVMediaTypeVideo, preferredTrackID: CMPersistentTrackID())
let assetVideoTrack: AVAssetTrack = asset!.tracksWithMediaType(AVMediaTypeVideo).first!
let chunkDuration = CMTimeSubtract(endTime, startTime)
let chunkTimeRange = CMTimeRangeMake(startTime, chunkDuration)
do {
try videoCompTrack.insertTimeRange(chunkTimeRange, ofTrack: assetVideoTrack, atTime: kCMTimeZero)
} catch let error as NSError {
print("Video reversing chunking failure: \(error)")
}
let exportSession = AVAssetExportSession(asset: composition, presetName: preferredPreset)
exportSession!.outputURL = chunkURL
exportSession!.outputFileType = AVFileTypeQuickTimeMovie
exportSession?.shouldOptimizeForNetworkUse = true
removeFileAtURLIfExists(chunkURL)
exportSession!.exportAsynchronouslyWithCompletionHandler({ () -> Void in
switch (exportSession!.status) {
case AVAssetExportSessionStatus.Completed:
NSLog("Export completed")
case AVAssetExportSessionStatus.Cancelled:
NSLog("Export cancelled")
break;
default:
NSLog("Export failed: \(exportSession?.error)")
}
})
And here is the error message:
2015-11-13 10:34:24.307 DemFishes[3501:63127] Export failed: Optional(Error Domain=NSURLErrorDomain Code=-3000 "Cannot create file" UserInfo={NSLocalizedDescription=Cannot create file, NSUnderlyingError=0x7ff5ee076460 {Error Domain=NSOSStatusErrorDomain Code=-12115 "(null)"}})
Any help is much appreciated, thanks!