4 Replies
      Latest reply on Jan 13, 2020 7:22 AM by Oioasdoij
      MarcoCarnevali Level 1 Level 1 (0 points)

        Hello guys, I constantly keep getting error code -12780 while saving the file.

        Configuration is

        AVAssetWriterInput(mediaType: AVMediaType.video, outputSettings: [
                        AVVideoCodecKey: AVVideoCodecType.h264,
                        AVVideoWidthKey: floor(UIScreen.main.bounds.width / 16) * 16,
                        AVVideoHeightKey: floor(UIScreen.main.bounds.height / 16) * 16,
                        AVVideoCompressionPropertiesKey: [
                            AVVideoAverageBitRateKey: 2300000,
                        ],
                        ])
        

        I don't understand what NSOSStatusErrorDomain -12780 means. The localized description is The operation could not be completed.

        Other than that I discovered that on my iOS 13 beta device the error code is: -17508, but still is The operation could not be completed.

        • Re: AVAssetWriter error code on finishWriting
          BruceLawton Level 1 Level 1 (0 points)

          iOS 13 is also giving me -17508 when trying to export video. The same code works on macOS. I can't find that error code in any headers.

            • Re: AVAssetWriter error code on finishWriting
              florianSAP Level 1 Level 1 (0 points)

              I am having the same issue (and same error code -17508) using AssetWriter to finisheWriting an .mp4 file with h.264 encoding into an App group's shared folder from a ReplayKit Upload Extension.

              I was not able to find -17508 anywhere, and the complete error is:

               

              Asset Writer Error: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-17508), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x280314d80 {Error Domain=NSOSStatusErrorDomain Code=-17508 "(null)

               

              Any ideas, what could be the issue?

               

              UPDATE: I figured out that in my case it was the output URL that was the problem.

              I used the following code to get the output URL of the folder shared (via App Group) between my app and my extension:

               

              let appGroupsFolderUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.mycompany")
              let outputURL = appGroupsFolderUrl!.appendingPathComponent("recording.mp4")

               

              Appears, you cannot store in that folder directly, but you need to store your file in a subfolder, e.g. like this:

               

              let appGroupsFolderUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.equalities")
              let outputURL = appGroupsFolderUrl!.appendingPathComponent("Library/Caches/recording.mp4")

               

              Note the Library/Caches part in the URL!

               

              Still, it is kind of ridiculous that in 21st century development frameworks, you still get a "-17508" error that is not listed anywhere, when really what should have been returned is a proper error describing what the actually problem is.

              • Re: AVAssetWriter error code on finishWriting
                dhavalconnect1990 Level 1 Level 1 (0 points)

                Hi @all,

                 

                I am facing the same issues in ios 13.3 in real device it is working in ios 13.2 simulator but gives below error.

                 

                Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-17508), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x2816d11d0 {Error Domain=NSOSStatusErrorDomain Code=-17508 "(null)"}}

                 

                 

                Here is my code I want to convert .mov file to mp4.

                class func encodeVideo(at videoURL: String, completionHandler: ((URL?, Error?) -> Void)?)  {
                        let avAsset = AVURLAsset(url: URL.init(fileURLWithPath: videoURL), options: nil)
                            
                        let startDate = Date()
                            
                        //Create Export session
                        guard let exportSession = AVAssetExportSession(asset: avAsset, presetName: AVAssetExportPresetPassthrough) else {
                            completionHandler?(nil, nil)
                            return
                        }
                            
                        //Creating temp path to save the converted video
                        let filename = "Video_\(Date().timeIntervalSince1970).mp4"
                          // Below Folder Path used tor getting directory path
                        let strfilePath = (FolderPath.temporaryDirectory.getDirectoryPath as NSString).appendingPathComponent(filename)
                        let filePath = URL.init(fileURLWithPath: strfilePath)
                            
                        //Check if the file already exists then remove the previous file
                        if FileManager.default.fileExists(atPath: filePath.path) {
                            do {
                                try FileManager.default.removeItem(at: filePath)
                            } catch {
                                completionHandler?(nil, error)
                            }
                        }
                            
                        exportSession.outputURL = filePath
                        exportSession.outputFileType = AVFileType.mp4
                        exportSession.shouldOptimizeForNetworkUse = true
                        let start = CMTimeMakeWithSeconds(0.0, preferredTimescale: 0)
                        let range = CMTimeRangeMake(start: start, duration: avAsset.duration)
                        exportSession.timeRange = range
                            
                        exportSession.exportAsynchronously(completionHandler: {() -> Void in
                            switch exportSession.status {
                            case .failed:
                                print(exportSession.error ?? "NO ERROR")
                                completionHandler?(nil, exportSession.error)
                            case .cancelled:
                                print("Export canceled")
                                completionHandler?(nil, nil)
                            case .completed:
                                //Video conversion finished
                                let endDate = Date()
                                    
                                let time = endDate.timeIntervalSince(startDate)
                                print(time)
                                print("Successful!")
                                print(exportSession.outputURL ?? "NO OUTPUT URL")
                                completionHandler?(exportSession.outputURL, nil)
                                    
                                default: break
                            }
                                
                        })
                    }