Record the screen on macOS
- macOS 13+
- Xcode 15+
- Swift 5.7+
Add the following to Package.swift
:
.package(url: "https://github.com/wulkano/Aperture", from: "3.0.0")
import Foundation
import Aperture
let recorder = Aperture.Recorder()
let screens = try await Aperture.Devices.screen()
guard let screen = screens.first else {
// No screens
exit(1)
}
try await recorder.start(
target: .screen,
options: Aperture.RecordingOptions(
destination: URL(filePath: "./screen-recording.mp4"),
targetID: screen.id,
)
)
try await Task.sleep(for: .seconds(5))
try await recorder.stop()
Type: URL
The filepath where the resulting recording should be written to.
Type: String
The ID of the target to record
Type: Bool
Default: false
Will use the lossless ALAC
codec if enabled, AAC
otherwise.
Type: Bool
Default: false
Record the system audio.
Type: String?
A microphone device ID to record.
Type: Int
Default: 60
Number of frames per seconds.
Type: Bool
Default: true
Show the cursor in the screen recording.
Type: Bool
Default: false
Highlight cursor clicks in the screen recording.
Note: This will only apply on macOS 15+
Type: Aperture.VideoCodec
Default: .h264
Values: .h264
, .hevc
, .proRes422
, .proRes4444
The video codec to be used.
Use Aeprture.Devices.screen
to discover the available screens
And then start recording with target: .screen
try await recorder.start(
target: .screen,
options: Aperture.RecordingOptions(
destination: fileURL,
targetID: screen.id,
framesPerSecond: 60,
cropRect: CGRect(x: 10, y: 10, width: 100, height: 100),
showCursor: true,
highlightClicks: true,
videoCodec: .h264,
losslessAudio: true,
recordSystemAudio: true,
microphoneDeviceID: microphone.id,
)
)
Accepts all the base video and audio options along with:
Type: CGRect?
Record only an area of the screen.
Use Aeprture.Devices.window
to discover the available windows
And then start recording with target: .window
try await recorder.start(
target: .window,
options: Aperture.RecordingOptions(
destination: fileURL,
targetID: window.id,
framesPerSecond: 60,
showCursor: true,
highlightClicks: true,
videoCodec: .h264,
losslessAudio: true,
recordSystemAudio: true,
microphoneDeviceID: microphone.id,
)
)
Accepts all the base video and audio options
Use Aeprture.Devices.audio
to discover the available audio devices
And then start recording with target: .audioOnly
try await recorder.start(
target: .audioOnly,
options: Aperture.RecordingOptions(
destination: fileURL,
losslessAudio: true,
recordSystemAudio: true,
microphoneDeviceID: microphone.id,
)
)
Accepts all the base audio options.
Use Aeprture.Devices.iOS
to discover the available external devices
And then start recording with target: .externalDevice
try await recorder.start(
target: .externalDevice,
options: Aperture.RecordingOptions(
destination: fileURL,
targetID: device.id,
framesPerSecond: 60,
videoCodec: .h264,
losslessAudio: true,
recordSystemAudio: true,
microphoneDeviceID: microphone.id,
)
)
Accepts the base video options except for cursor related ones, and all the audio options.
let screens = try await Aperture.Devices.screen()
let windows = try await Aperture.Devices.window(excludeDesktopWindows: true, onScreenWindowsOnly: true)
Type: Bool
Default: true
Type: Bool
Default: true
let devices = Aperture.Devices.audio()
let devices = Aperture.Devices.iOS()
Run ./example.sh
or ./example-ios.sh
.
- aperture-node - Node.js wrapper