Skip to content

Commit 9724012

Browse files
committed
updates VideoWriter
1 parent 3ac899d commit 9724012

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

Client/source.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ public struct MainApp {
1010

1111
public static func main() async throws {
1212

13-
try await Mouse.drag(from: CGPoint(x: 400, y: 400), to: CGPoint(x: 500, y: 500))
13+
let writer = try Screen.record(to: .desktopDirectory.appending(path: "file.m4v"))
14+
try await Task.sleep(for: .seconds(2))
15+
try await writer.finish()
1416

1517
}
1618

Sources/ControlKit/Screen/Screen.swift

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ public struct Screen {
235235
nonisolated(unsafe)
236236
let produce = produce
237237

238+
nonisolated(unsafe)
239+
let converter = MetalImageConverter()
240+
238241
assetWriterVideoInput.requestMediaDataWhenReady(on: mediaQueue) { [unowned self] in
239242
guard assetWriterVideoInput.isReadyForMoreMediaData else { return } // go on waiting
240243
guard !isFinished else {
@@ -272,26 +275,13 @@ public struct Screen {
272275
while _frame == nil {
273276
_frame = produce()
274277
}
278+
let frame = _frame!
275279

276280
// Draw image into context
277281

278282
preparePixelQueue.sync { } // wait for the queue
279283

280-
// converter.convertImageToPixelBuffer(frame, pixelBuffer: pixelBuffer, size: size)
281-
// if size == frame.size {
282-
// } else {
283-
// CVPixelBufferLockBaseAddress(pixelBuffer, CVPixelBufferLockFlags(rawValue: CVOptionFlags(0)))
284-
//
285-
// let pixelData = CVPixelBufferGetBaseAddress(pixelBuffer)
286-
//
287-
// let context = CGContext(data: pixelData, width: Int(size.width), height: Int(size.height), bitsPerComponent: 8, bytesPerRow: CVPixelBufferGetBytesPerRow(pixelBuffer), space: frame.colorSpace!, bitmapInfo: CGImageAlphaInfo.premultipliedFirst.rawValue | CGBitmapInfo.byteOrder32Little.rawValue)!
288-
//
289-
//
290-
//
291-
// context.draw(frame, in: drawCGRect) // takes most time
292-
//
293-
// CVPixelBufferUnlockBaseAddress(pixelBuffer, CVPixelBufferLockFlags(rawValue: CVOptionFlags(0)))
294-
// }
284+
converter.convertImageToPixelBuffer(frame, pixelBuffer: pixelBuffer, size: size)
295285

296286
assert(assetWriter.status == .writing)
297287
assert(assetWriterVideoInput.isReadyForMoreMediaData)

0 commit comments

Comments
 (0)