我正在处理一个任务,需要按照用户输入或选择的特定开始点和结束点剪辑录制的视频。我应该如何做到这一点呢?之前我使用过 UIVideoEditorController
,但我不想使用默认视图,而是直接剪辑视频。
let FinalUrlTosave = NSURL(string: "\(newURL)")
exportSession!.outputURL=FinalUrlTosave
exportSession!.shouldOptimizeForNetworkUse = true
// exportSession.outputFileType = AVFileTypeQuickTimeMovie
exportSession!.outputFileType = AVFileTypeQuickTimeMovie;
let start:CMTime
let duration:CMTime
var st = starttime.doubleValue
var ed = endTime.doubleValue
start = CMTimeMakeWithSeconds(st, 600)
duration = CMTimeMakeWithSeconds(ed, 600)
// let timeRangeForCurrentSlice = CMTimeRangeMake(start, duration)
let range = CMTimeRangeMake(start, duration);
exportSession!.timeRange = range
exportSession!.exportAsynchronouslyWithCompletionHandler({
switch exportSession!.status{
case AVAssetExportSessionStatus.Failed:
print("failed \(exportSession!.error)")
case AVAssetExportSessionStatus.Cancelled:
print("cancelled \(exportSession!.error)")
default:
print("complete....complete")
// self.SaveVideoToPhotoLibrary(destinationURL1!)
}
})
我尝试使用这个方法来实现我的目标,但没有成功。
错误信息:
失败的可选(Error Domain=NSURLErrorDomain Code=-1100 "服务器上未找到所请求的URL。" UserInfo={NSErrorFailingURLStringKey=file:///var/mobile/Containers/Data/Application/E68D3BFD-6923-4EA6-9FB3-C020CE4AA9D4/Documents/moment/jGq_9AUFa47s2ZiiPP4x.mp4, NSErrorFailingURLKey=file:///var/mobile/Containers/Data/Application/E68D3BFD-6923-4EA6-9FB3-C020CE4AA9D4/Documents/moment/jGq_9AUFa47s2ZiiPP4x.mp4, NSLocalizedDescription=服务器上未找到所请求的URL。, NSUnderlyingError=0x1553c220 {Error Domain=N
第二次发生错误:
失败的可选(Error Domain=NSURLErrorDomain Code=-3000 "无法创建文件" UserInfo={NSUnderlyingError=0x14e00000 {Error Domain=NSOSStatusErrorDomain Code=-12124 "(null)"}, NSLocalizedDescription=无法创建文件})
NSURL(string: "...")
会出现意外情况。如果是本地文件,请尝试使用NSURL(fileURLWithPath: "...")
。 - hola