I am trying to crop a video file before uploading to FireStore. The code I am using is as below:
And this is how I crop the video: https://gist.github.com/vakhidbetrakhmadov/1402653b6f3e5ca99923a90ff8763b9c
If I upload the video directly from 'outputFileURL' from didFinishRecording, there is no problem. But when I use 'exportURL' it won't work. Strange thing is I can play the cropped video using the same URL (exportURL). This is the debug log:
Can anyone see what I am doing wrong here?
Code Block func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?) { // Note: Because we use a unique file path for each recording, a new recording won't overwrite a recording mid-save. isRecording = false let exportPath = NSTemporaryDirectory().appendingFormat("\(randomString(length: 5)).MOV") let exportURL = URL(fileURLWithPath: exportPath) let asset = AVAsset(url: outputFileURL) let clipVideoTrack = asset.tracks( withMediaType: AVMediaType.video ).first! as AVAssetTrack let rect = CGRect(x: 0, y: 0, width: clipVideoTrack.naturalSize.height, height: clipVideoTrack.naturalSize.height) asset.cropVideoTrack(at: 0, cropRect: rect, outputURL: exportURL) { result in switch result { case .success(): self.videoURL = exportURL self.postPicture(postURL: exportURL) self.isTaken = true var success = true ......
And this is how I crop the video: https://gist.github.com/vakhidbetrakhmadov/1402653b6f3e5ca99923a90ff8763b9c
If I upload the video directly from 'outputFileURL' from didFinishRecording, there is no problem. But when I use 'exportURL' it won't work. Strange thing is I can play the cropped video using the same URL (exportURL). This is the debug log:
Code Block Post picture to database here Video to play: file:///private/var/mobile/Containers/Data/Application/AA73684B-4199-47DB-954A-F6FD5AE3C8B5/tmp/6WYy2.MOV 2021-05-21 23:58:12.426620+0300 DogGram[91943:9315533] Body file is unreachable: /private/var/mobile/Containers/Data/Application/AA73684B-4199-47DB-954A-F6FD5AE3C8B5/tmp/6WYy2.MOV Error Domain=NSCocoaErrorDomain Code=260 "The file “6WYy2.MOV” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///private/var/mobile/Containers/Data/Application/AA73684B-4199-47DB-954A-F6FD5AE3C8B5/tmp/6WYy2.MOV, NSFilePath=/private/var/mobile/Containers/Data/Application/AA73684B-4199-47DB-954A-F6FD5AE3C8B5/tmp/6WYy2.MOV, NSUnderlyingError=0x281102880 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
Can anyone see what I am doing wrong here?