简体   繁体   中英

AVAssetExportSession export failure NSURLErrorDomain Code-=3000 (Swift)

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!

Found my mistake. chunkURL is not a valid url

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM