26837

Video Trimming failed with block AVAssetExportSessionStatus.Failed

Question:

I have converted <a href="https://stackoverflow.com/questions/31070941/how-to-trim-the-video-file-and-convert-to-20-seconds-video-with-swift/31072103#31072103" rel="nofollow">this</a> code to Swift language but i am getting this

<blockquote>

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).

</blockquote>

Kindly help me to resolved this

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!) } }) } <hr /> 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") } } }

Answer1:

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

let FinalUrlTosave = NSURL(fileURLWithPath: outputURL)

instead of

let FinalUrlTosave = NSURL(string: outputURL)

I was not getting exact path.

Recommend

  • Possible to pass `p:inputText` parameters via `f:param`? [closed]
  • Looping an xml parser till a tag is done
  • swift: how to delete part of audio?
  • Is looping through all style sheets and classes a good idea in JavaScript?
  • Google map in top corner left
  • Angular Bootstrap Carousel Slide Transition not working correctly
  • jQuery - resize an elements height to match window without refreshing, on window resize
  • Can't get plist URL in Swift
  • Google OAuth: can't get refresh token with authorization code
  • Why people use prototype in javascript when it is easy to inherit using apply () and call () methods
  • Creating a Multidimensional, Associative Array in VBScript
  • Responsive design method for collapsing a div
  • unable to get jsonEncode in magento2
  • Cannot get text from text area
  • How to load gif image while ajax content is loading and javascript [duplicate]
  • converter json to two dimensional array
  • Getting error 'Cannot read property 'document' of undefined' while importing exp
  • Primefaces :radioButton inside a ui:repeat
  • Owin Authentication and claims in asp.net how to access user data
  • Update Google Maps traffic layer without page reloading
  • SQLite connection strategies
  • Remove changes from one element when event occurs on another element?
  • How to remove a SwiftyJSON element?
  • Convert Type Decimal to Hex (string) in .NET 3.5
  • How do I pass the string value parameter of the selected list item from an auto-populated dropdown l
  • Allowing both email and username for authentication
  • jQuery .attr() and value
  • Email format validation in mvc3 view
  • Regex thinks I'm nesting, but I'm not
  • req.body is undefined - nodejs
  • How to get a value (ex: baseURL) in every Karate feature?
  • angularjs unit test when to use $rootScope.$new()
  • How to set/get protobuf's extension field in Go?
  • Submit form in a displaytag pagination
  • Can I have the cursor start on a particular column by default in jqgrid's edit mode?
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • How to delete a row from a dynamic generate table using jquery?
  • using HTMLImports.whenReady not working in chrome
  • Authorize attributes not working in MVC 4
  • EntityFramework adding new object to nested object collection