LightCompressor_iOS icon indicating copy to clipboard operation
LightCompressor_iOS copied to clipboard

Crash

Open CricHeroesiOS opened this issue 5 years ago • 18 comments

** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '*** -[AVAssetReader startReading] cannot be called again after reading has already started'

CricHeroesiOS avatar Nov 25 '20 13:11 CricHeroesiOS

I'm also seeing this same crash, using default implementation as recommend from README.

pouty18 avatar Dec 29 '20 01:12 pouty18

+1

nmohamedtharik avatar Feb 16 '21 16:02 nmohamedtharik

Thank you for opening this issue. I will look into it and fix it in a couple of days.

AbedElazizShe avatar Feb 16 '21 17:02 AbedElazizShe

+1 same issue

kientrung0412 avatar Feb 25 '21 03:02 kientrung0412

Could you please let me know what is the scenario that leads to this issue? I understand what the problem is, but surprised that it happens and I can't produce it. Any details could help me fix it. Thank you. @kientrung0412 @nmohamedtharik @pouty18

AbedElazizShe avatar Feb 26 '21 14:02 AbedElazizShe

+1 Same issue

Crash at this line : let sampleBuffer:CMSampleBuffer? = audioReaderOutput.copyNextSampleBuffer()

Screenshot 2021-03-01 at 11 00 42 AM

DixPatel009 avatar Mar 01 '21 05:03 DixPatel009

@AbedElazizShe it's not crash if i using your example, only crash if use the LightCompressor.swift in the library.it's crash on the same line as @DixPatel009 mention above

kientrung0412 avatar Mar 01 '21 06:03 kientrung0412

Thank you @DixPatel009 and @kientrung0412. This is a great information and sorry it is happening to you. I will work on fixing that tomorrow. I will notify you when that is done. Cheers.

AbedElazizShe avatar Mar 03 '21 15:03 AbedElazizShe

@AbedElazizShe any updates on crash fix?

BasavarajIOS avatar Mar 17 '21 13:03 BasavarajIOS

@AbedElazizShe any updates on crash ?

ghimireprashant avatar Mar 25 '21 07:03 ghimireprashant

@ghimireprashant @BasavarajIOS Could you please try to update to the latest version? 0.1.8. I can't produce the issue at all, so the fix is not tested.

If it is still not working, please provide me a sample code where the issue happens. Thank you.

AbedElazizShe avatar Mar 28 '21 13:03 AbedElazizShe

@AbedElazizShe i tried on latest version. Just try to compress multiple video at once you will get that error. for refence: let destination = [videoToCompress, videoToCompress, videoToCompress, videoToCompress] for item in destination { let startingPoint = Date() let videoCompressor = LightCompressor()

    compression = videoCompressor.compressVideo(source: item,
                                                destination: destinationPath as URL,
                                                quality: .medium,
                                                isMinBitRateEnabled: true,
                                                keepOriginalResolution: false,
                                                progressQueue: .main,
                                                progressHandler: { progress in
                                                  DispatchQueue.main.async { [unowned self] in
                                                    self.progressBar.progress = Float(progress.fractionCompleted)
                                                    self.progressLabel.text = "\(String(format: "%.0f", progress.fractionCompleted * 100))%"
                                                  }},
                                                
                                                completion: {[weak self] result in
                                                  guard let `self` = self else { return }
                                                  
                                                  switch result {
                                                  
                                                  case .onSuccess(let path):
                                                    self.compressedPath = path
                                                    DispatchQueue.main.async { [unowned self] in
                                                      self.sizeAfterCompression.isHidden = false
                                                      self.duration.isHidden = false
                                                      self.progressBar.isHidden = true
                                                      self.progressLabel.isHidden = true
                                                      
                                                      self.sizeAfterCompression.text = "Size after compression: \(path.fileSizeInMB())"
                                                      self.duration.text = "Duration: \(String(format: "%.2f", startingPoint.timeIntervalSinceNow * -1)) seconds"
                                                      
                                                      PHPhotoLibrary.shared().performChanges({
                                                        PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: path)
                                                      })
                                                    }
                                                    
                                                  case .onStart:
                                                    self.progressBar.isHidden = false
                                                    self.progressLabel.isHidden = false
                                                    self.sizeAfterCompression.isHidden = true
                                                    self.duration.isHidden = true
                                                  //self.originalSize.visiblity(gone: false)
                                                  
                                                  case .onFailure(let error):
                                                    self.progressBar.isHidden = true
                                                    self.progressLabel.isHidden = false
                                                    self.progressLabel.text = (error as! CompressionError).title
                                                    
                                                    
                                                  case .onCancelled:
                                                    print("---------------------------")
                                                    print("Cancelled")
                                                    print("---------------------------")
                                                  }
                                                })
  }

Thank you. :)

ghimireprashant avatar Mar 29 '21 03:03 ghimireprashant

I still get that error with 0.1.8. Funny thing, it doesn't happen in the demo app, even when calling the library with the same parameters and using the same video 🤔

puelocesar avatar Apr 08 '21 14:04 puelocesar

Ok, my version was crashing because I was saving the final destination in the same folder as the "tmp" file I got from the Media Library, I was doing something like this:

let finalURL = url.deletingLastPathComponent().appendingPathComponent("compressed.mp4")

Probably that folder gets deleted while compressing and the whole thing breaks, it started working after I changed my code to save the destination in a proper tmp folder like in the sample:

let destinationPath = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("compressed.mp4")
try? FileManager.default.removeItem(at: destinationPath)

puelocesar avatar Apr 08 '21 14:04 puelocesar

+1, Multiple video leads to

Boy-Rong avatar Apr 28 '21 03:04 Boy-Rong

Thank you for all the information and sorry for the late reply. Knowing the scenario will make it easier to fix, will test multiple video selection and try to fix the issue as soon as possible.

AbedElazizShe avatar Apr 30 '21 16:04 AbedElazizShe

I had this problem too, but once I set my destination path to

let destination = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("\(UUID().uuidString).mp4")

it works totally fine with either single or when looping over videos. When I download the app container, they're all in the tmp directory, compressed af 👍

luke-riu avatar May 13 '21 13:05 luke-riu

I realized this crash but this was my fault. outputURL that given to AVAssetWriter was not existing directory. Fixed when set existing folder or temporaryFolder. ℹ️

huseyinmetin avatar Feb 23 '23 08:02 huseyinmetin