From 7b3e260d57a33582bfc862c50084f0e71bd59306 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Fri, 2 Jan 2026 14:49:54 +0000 Subject: [PATCH] started gpu encoding (idk if it works yet) --- CaptureEngine.swift | 26 +++++++++++++++++++++++++- Scream/AppDelegate.swift | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CaptureEngine.swift b/CaptureEngine.swift index f049dab..7ea579c 100644 --- a/CaptureEngine.swift +++ b/CaptureEngine.swift @@ -7,6 +7,7 @@ import Foundation import ScreenCaptureKit +import VideoToolbox struct CapturedFrame { static var invalid: CapturedFrame { @@ -30,7 +31,30 @@ class CaptureEngine: NSObject { private var continuation: AsyncThrowingStream.Continuation? func startCapture(config: SCStreamConfiguration, filter: SCContentFilter) -> AsyncThrowingStream { - AsyncThrowingStream { continuation in + let videoEncoderSpec = [kVTVideoEncoderSpecification_EnableLowLatencyRateControl: true as CFBoolean] as CFDictionary + + let sourceImageBufferAttrs = [kCVPixelBufferPixelFormatTypeKey: 1 as CFNumber] as CFDictionary + var compressionSessionOut: VTCompressionSession? + let err = VTCompressionSessionCreate( + allocator: kCFAllocatorDefault, + width: 1600, + height: 900, + codecType: kCMVideoCodecType_H264, + encoderSpecification: videoEncoderSpec, + imageBufferAttributes: sourceImageBufferAttrs, + compressedDataAllocator: nil, + outputCallback: { outputCallbackRefCon, sourceFrameRefCon, status, infoFlags, samplebuffer in + print(status) + }, + refcon: nil, + compressionSessionOut: &compressionSessionOut + ) + + guard err == noErr, let compressionSession = compressionSessionOut else { + fatalError() + } + + return AsyncThrowingStream { continuation in let streamOutput = StreamHandler(continuation: continuation) self.streamOutput = streamOutput streamOutput.frameBufferHandler = { continuation.yield($0) } diff --git a/Scream/AppDelegate.swift b/Scream/AppDelegate.swift index 3c311d5..492db7d 100644 --- a/Scream/AppDelegate.swift +++ b/Scream/AppDelegate.swift @@ -24,6 +24,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { let preview = CaptureVideoPreview(layer: sr.contentLayer) preview.frame.size = window.contentView!.frame.size window.contentView?.addSubview(preview) + Button(self) } func applicationWillTerminate(_ aNotification: Notification) {