Aperture

在 macOS 上录制屏幕

要求

安装

将以下内容添加到 Package.swift

.package(url: "https://github.com/wulkano/Aperture", from: "3.0.0")

或者在 Xcode 中添加软件包。

文档

API 文档。

基本用法

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

结果录制内容应写入的文件路径。

目标 ID

类型: String

要录制的目标的 ID

基本音频选项

无损音频

类型: Bool
默认值: false

如果启用,将使用无损的 ALAC 编解码器,否则使用 AAC

录制系统音频

类型: Bool
默认值: false

录制系统音频。

麦克风设备 ID

类型: 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

相关