Hello,
I'm finding that AVAssetWriter status is failing in the middle of recording frames obtained using RPScreenRecorder::startCapture. The failure seems to occur about a minute and half into a recording. The error code when asked from AVAssetWriter is -11847. It appears that error code is usually thrown when the app is backgrounded but in my case the app is never backgrounded. This error happens once every 2-3 runs on my iPhone 12 Pro Max. It's also reproducible on an iPhone 11. iOS version is 15.1.1.
Any clues as to why this might be occurring? Thanks in advance.
Note I'm using movieFragmentInterval on an mp4 file. I couldn't tell from the documentation if its only for QuickTime files or not.
I'm setting up an AVAssetWriter like so. Code simplified for readability.
let assetWriter = try? AVAssetWriter(outputURL: fileURL, fileType: AVFileType.mp4)!
assetWriter.movieFragmentInterval = CMTimeMakeWithSeconds(60, preferredTimescale: 1000)
let preset = AVOutputSettingsAssistant(preset: .preset1280x720)
var outputSettings = preset?.videoSettings
outputSettings?[AVVideoScalingModeKey] = AVVideoScalingModeResizeAspect
var compressionSettings = outputSettings?[AVVideoCompressionPropertiesKey] as? [String:Any]
var bitRate:Float = 4.0
compressionSettings?[AVVideoAverageBitRateKey] = NSNumber(value:720.0 * 1280.0 * bitRate)
outputSettings?[AVVideoCompressionPropertiesKey] = compressionSettings
videoInput = AVAssetWriterInput(mediaType: AVMediaType.video, outputSettings: outputSettings)
videoInput.expectsMediaDataInRealTime = true
assetWriter.add(videoInput)
let audioOutputSettings = preset?.audioSettings
audioInput = AVAssetWriterInput(mediaType: .audio, outputSettings: audioOutputSettings)
audioInput.expectsMediaDataInRealTime = true;
assetWriter.add(audioInput)
assetWriter.startWriting()