AVAssetExportSession导出失败NSURLErrorDomain Code- = 3000(Swift)

时间:2015-11-12 21:43:51

标签: swift avfoundation avassetexportsession

这是我的代码:

            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)")
                }
            })

以下是错误消息:

  

2015-11-13 10:34:24.307 DemFishes [3501:63127]出口失败:   可选(错误域= NSURLErrorDomain代码= -3000“无法创建文件”   UserInfo = {NSLocalizedDescription =无法创建文件,   NSUnderlyingError = 0x7ff5ee076460 {错误域= NSOSStatusErrorDomain   代码= -12115“(null)”}})

非常感谢任何帮助,谢谢!

1 个答案:

答案 0 :(得分:2)

发现我的错误。 chunkURL不是有效的网址