ScreenCaptureKit - Sample project doesn't work on macOS Sonoma

I'm getting this error when I try to run the ScreenCaptureKit sample project on macOS Sonoma:

[ERROR] _SCStream_RemoteAudioQueueOperationHandlerWithError:1,053 streamOutput NOT found. Dropping frame
[ERROR] _SCStream_RemoteVideoQueueOperationHandlerWithError:1,020 stream output NOT found. Dropping frame

Both streamOutput are being set like this:

try stream?.addStreamOutput(streamOutput, type: .screen, sampleHandlerQueue: videoSampleBufferQueue)
try stream?.addStreamOutput(streamOutput, type: .audio, sampleHandlerQueue: audioSampleBufferQueue)

Link to sample project https://developer.apple.com/documentation/screencapturekit/capturing_screen_content_in_macos

Any idea of what is causing this?

Accepted Reply

I downloaded the sample project as well and I was getting the same error.

Funnily enough, an idea came to my mind while showering. Maybe now in Sonoma SCStream keeps a weak reference to the outputs, and because the sample project declares the CaptureEngineStreamOutput instance locally, it gets discarded right away. That was my guess.

I came back to the Xcode and confirmed when I saw this line:

func startCapture(configuration: SCStreamConfiguration, filter: SCContentFilter) -> AsyncThrowingStream<CapturedFrame, Error> {
    AsyncThrowingStream<CapturedFrame, Error> { continuation in
            // The stream output object.
            let output = CaptureEngineStreamOutput(continuation: continuation)

So I declared right above the method a property to keep the reference alive:

private var streamOutput: CaptureEngineStreamOutput?

And then, assign the local property to the instance one:

streamOutput = output

That immediately fixed the error!

Replies

Did you get to the bottom of this? I am also experiencing it. Weirdly, the sample project worked for me the first couple of compiles, and then without any code changes this error started spewing in the logs and the capture preview is solid black.

  • The first error I see in the logs is "unexpected error getting preference domain for service com.apple.cmio.registerassistantservice.system-extensions: Connection invalid". Searching that string does not turn up anything on google. I'm on Sonoma 14.0 Beta (23A5286i).

Add a Comment

@lzell I was able to "fix" it by changing the CaptureEngine class to also implement SCStreamOutput and SCStreamDelegate. So now, I'm sending self instead of streamOutput to addStreamOutput.

try stream?.addStreamOutput(self, type: .screen, sampleHandlerQueue: videoSampleBufferQueue)
  • Thank you! I just came back to this project. I'm happy to see @Natan's find below too!

Add a Comment

I downloaded the sample project as well and I was getting the same error.

Funnily enough, an idea came to my mind while showering. Maybe now in Sonoma SCStream keeps a weak reference to the outputs, and because the sample project declares the CaptureEngineStreamOutput instance locally, it gets discarded right away. That was my guess.

I came back to the Xcode and confirmed when I saw this line:

func startCapture(configuration: SCStreamConfiguration, filter: SCContentFilter) -> AsyncThrowingStream<CapturedFrame, Error> {
    AsyncThrowingStream<CapturedFrame, Error> { continuation in
            // The stream output object.
            let output = CaptureEngineStreamOutput(continuation: continuation)

So I declared right above the method a property to keep the reference alive:

private var streamOutput: CaptureEngineStreamOutput?

And then, assign the local property to the instance one:

streamOutput = output

That immediately fixed the error!