I'm trying to use ScreenCaptureKit to write an app that will record meetings. However, anytime I instantiate an AVAssetWriter and start streaming CMSampleBuffers to it, it will fail with the error
Optional(Error Domain=AVFoundationErrorDomain Code=-11800 \"The operation could not be completed\" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12785), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x600000c066d0 {Error Domain=NSOSStatusErrorDomain Code=-12785 \"(null)\"}})
I've got a full code reproduction at this repo - https://github.com/jonluca/buggy-avassetwriter
What's weird is that this repo works, where it's ~95% the same code https://github.com/garethpaul/ScreenRecorderMacOS
I might just not be attuned to the intricacies of AVAssetWriter and the newer ScreenCaptureKit, but I'm just not sure how this error can be happening.
Alright this took a while to figure out but it turns out that you can't only check if a
CMSampleBufferis valid. It looks like it can still be invalid, so I added a util calledisValidFramethat checks the SCFrameStatus option, as well as a few other keys