在 macOS 上录制屏幕
将以下内容添加到 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()
类型: URL
结果录制内容应写入的文件路径。
类型: String
要录制的目标的 ID
类型: Bool
默认值: false
如果启用,将使用无损的 ALAC
编解码器,否则使用 AAC
。
类型: Bool
默认值: false
录制系统音频。
类型: String?
要录制的麦克风设备 ID。
类型: Int
默认值: 60
每秒帧数。
类型: Bool
默认值: true
在屏幕录制中显示光标。
类型: Bool
默认值: false
在屏幕录制中高亮光标点击。
注意: 此功能仅在 macOS 15+ 上适用
类型: Aperture.VideoCodec
默认值: .h264
可选值: .h264
, .hevc
, .proRes422
, .proRes4444
要使用的视频编解码器。
使用 Aeprture.Devices.screen
来发现可用的屏幕
然后使用 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,
)
)
类型: CGRect?
仅录制屏幕的某个区域。
使用 Aeprture.Devices.window
来发现可用的窗口
然后使用 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,
)
)
使用 Aeprture.Devices.audio
来发现可用的音频设备
然后使用 target: .audioOnly
开始录制
try await recorder.start(
target: .audioOnly,
options: Aperture.RecordingOptions(
destination: fileURL,
losslessAudio: true,
recordSystemAudio: true,
microphoneDeviceID: microphone.id,
)
)
接受所有基本的 音频 选项。
使用 Aeprture.Devices.iOS
来发现可用的外部设备
然后使用 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,
)
)
接受基本的 视频 选项(光标相关的选项除外)以及所有 音频 选项。
let screens = try await Aperture.Devices.screen()
let windows = try await Aperture.Devices.window(excludeDesktopWindows: true, onScreenWindowsOnly: true)
类型: Bool
默认值: true
类型: Bool
默认值: true
let devices = Aperture.Devices.audio()
let devices = Aperture.Devices.iOS()
运行 ./example.sh
或 ./example-ios.sh
。