mirror of
https://github.com/neon443/Scream.git
synced 2026-03-11 05:19:14 +00:00
started gpu encoding (idk if it works yet)
This commit is contained in:
@@ -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<CapturedFrame, Error>.Continuation?
|
||||
|
||||
func startCapture(config: SCStreamConfiguration, filter: SCContentFilter) -> AsyncThrowingStream<CapturedFrame, Error> {
|
||||
AsyncThrowingStream<CapturedFrame, Error> { 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<CapturedFrame, Error> { continuation in
|
||||
let streamOutput = StreamHandler(continuation: continuation)
|
||||
self.streamOutput = streamOutput
|
||||
streamOutput.frameBufferHandler = { continuation.yield($0) }
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user