视频修剪失败,块AVAssetExportSessionStatus.Failed [英] Video Trimming failed with block AVAssetExportSessionStatus.Failed

查看:94
本文介绍了视频修剪失败,块AVAssetExportSessionStatus.Failed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经转换了

I have converted this code to Swift language but i am getting this

错误:错误域= AVFoundationErrorDomain代码= -11800操作无法完成" UserInfo = 0x174278600 {NSUnderlyingError = 0x170241d10操作无法完成.(OSStatus错误-12780.)",NSLocalizedFailureReason =未知错误发生(-12780),NSLocalizedDescription =操作无法完成}(情况为AVAssetExportSessionStatus.Failed).

Error: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x174278600 {NSUnderlyingError=0x170241d10 "The operation couldn’t be completed. (OSStatus error -12780.)", NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed} in (case AVAssetExportSessionStatus.Failed).

请帮助我解决此问题

func cropVideo(sourceURL: NSURL)
    {
        let asset = AVURLAsset(URL: sourceURL, options: nil)

        let exportSession = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetHighestQuality)
                var error : NSError?
   let file = "Finaloutput.mp4"
     /*   let paths : AnyObject = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask,true)[0]
        let outputURL1 = paths[0] as? String*/
        let nsDocumentDirectory = NSSearchPathDirectory.DocumentDirectory
        let nsUserDomainMask = NSSearchPathDomainMask.UserDomainMask
        let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true)

        let outputURL1 = paths[0] as? String

        let filemgr = NSFileManager.defaultManager()
        filemgr.createDirectoryAtPath(outputURL1!, withIntermediateDirectories: true, attributes: nil, error: &error)
        var outputURL = outputURL1!.stringByAppendingPathComponent(file)
        filemgr.removeItemAtPath(outputURL, error: &error)

        let FinalUrlTosave = NSURL(string: outputURL)
        exportSession.outputURL=FinalUrlTosave
        exportSession.shouldOptimizeForNetworkUse = true
        // exportSession.outputFileType = AVFileTypeQuickTimeMovie
        exportSession.outputFileType = AVFileTypeQuickTimeMovie;
        let start:CMTime
        let duration:CMTime
         start = CMTimeMakeWithSeconds(1.0, 600)
         duration = CMTimeMakeWithSeconds(19.0, 600)
        // let timeRangeForCurrentSlice = CMTimeRangeMake(start, duration)
        let range = CMTimeRangeMake(start, duration);
        exportSession.timeRange = range

        let destinationURL1 = NSURL(string: outputURL)

        exportSession.exportAsynchronouslyWithCompletionHandler({
            switch exportSession.status{
            case  AVAssetExportSessionStatus.Failed:

                println("failed \(exportSession.error)")
            case AVAssetExportSessionStatus.Cancelled:
                println("cancelled \(exportSession.error)")
            default:
                println("complete....complete")
                self.SaveVideoToPhotoLibrary(destinationURL1!)

            }
        })
    }


  func SaveVideoToPhotoLibrary(outputFileURL: NSURL)

    {


        assetsLibrary = ALAssetsLibrary()

        let videoURL = outputFileURL as NSURL?

        if let library = assetsLibrary{

            if let url = videoURL{

                library.writeVideoAtPathToSavedPhotosAlbum(url,
                    completionBlock: {(url: NSURL!, error: NSError!) in

                        print(url)

                        if let theError = error{
                            print("Error happened while saving the video")
                            print("The error is = \(theError)")
                        } else {
                            print("no errors happened")
                        }

                })
            } else {
                print("Could not find the video in the app bundle")
            }

        }


    }

推荐答案

找到的解决方案:我更改了此行,它对我有用

Found Solution : I have change this line and it works for me

 let FinalUrlTosave = NSURL(fileURLWithPath: outputURL)

代替

let FinalUrlTosave = NSURL(string: outputURL)

我没有得到确切的路径.

I was not getting exact path.

这篇关于视频修剪失败,块AVAssetExportSessionStatus.Failed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆