diff --git a/Package.resolved b/Package.resolved index d1a7a8e..40d2a09 100644 --- a/Package.resolved +++ b/Package.resolved @@ -15,8 +15,8 @@ "repositoryURL": "https://github.com/apple/swift-argument-parser", "state": { "branch": null, - "revision": "47bd06ebeff8146ecd0020809e186218b46f465f", - "version": "0.4.2" + "revision": "986d191f94cec88f6350056da59c2e59e83d1229", + "version": "0.4.3" } } ] diff --git a/Sources/ApertureCLI/record.swift b/Sources/ApertureCLI/record.swift index 0c8df69..3f0fc80 100644 --- a/Sources/ApertureCLI/record.swift +++ b/Sources/ApertureCLI/record.swift @@ -10,6 +10,7 @@ struct Options: Decodable { let screenId: CGDirectDisplayID let audioDeviceId: String? let videoCodec: String? + let scaleFactor: Double? } func record(_ optionsString: String, processId: String) throws { @@ -25,7 +26,8 @@ func record(_ optionsString: String, processId: String) throws { highlightClicks: options.highlightClicks, screenId: options.screenId == 0 ? .main : options.screenId, audioDevice: options.audioDeviceId != nil ? AVCaptureDevice(uniqueID: options.audioDeviceId!) : nil, - videoCodec: options.videoCodec != nil ? AVVideoCodecType(rawValue: options.videoCodec!) : nil + videoCodec: options.videoCodec != nil ? AVVideoCodecType(rawValue: options.videoCodec!) : nil, + scaleFactor: options.scaleFactor != nil ? options.scaleFactor! : 1 ) recorder.onStart = { diff --git a/index.d.ts b/index.d.ts index e6f993a..b671a31 100644 --- a/index.d.ts +++ b/index.d.ts @@ -61,6 +61,13 @@ declare namespace aperture { The `proRes422` and `proRes4444` codecs are uncompressed data. They will create huge files. */ readonly videoCodec?: VideoCodec; + + /** + Scale factor to use + The actual height and width of the capture will be multiplied by this number to create the height and width of the output. + @default 1 + */ + readonly scaleFactor?: number; }; interface Recorder { @@ -101,6 +108,11 @@ declare namespace aperture { Returns a `Promise` for the path to the screen recording file. */ stopRecording: () => Promise; + + /** + Cancels a recording, if it was started + */ + cancel: () => void; } } diff --git a/index.js b/index.js index 7607da0..67758b9 100644 --- a/index.js +++ b/index.js @@ -39,6 +39,9 @@ class Aperture { macosVersion.assertGreaterThanOrEqualTo('10.13'); } + + recorderTimeout = undefined + startRecording({ fps = 30, cropArea = undefined, @@ -46,7 +49,8 @@ class Aperture { highlightClicks = false, screenId = 0, audioDeviceId = undefined, - videoCodec = undefined + videoCodec = undefined, + scaleFactor = 1 } = {}) { this.processId = getRandomId(); @@ -80,7 +84,8 @@ class Aperture { showCursor, highlightClicks, screenId, - audioDeviceId + audioDeviceId, + scaleFactor }; if (cropArea) { @@ -123,7 +128,7 @@ class Aperture { return this.tmpPath; })(); - const timeout = setTimeout(() => { + this.recorderTimeout = setTimeout(() => { // `.stopRecording()` was called already if (this.recorder === undefined) { return; @@ -137,7 +142,7 @@ class Aperture { }, 5000); this.recorder.catch(error => { - clearTimeout(timeout); + clearTimeout(recorderTimeout); delete this.recorder; reject(error); }); @@ -148,7 +153,7 @@ class Aperture { (async () => { try { await this.waitForEvent('onStart'); - clearTimeout(timeout); + clearTimeout(recorderTimeout); setTimeout(resolve, 1000); } catch (error) { reject(error); @@ -227,6 +232,19 @@ class Aperture { return this.tmpPath; } + + cancel() { + if (this.recorder === undefined) { + return + } + + this.recorder.kill(); + delete this.recorder; + delete this.isFileReady; + if (this.recorderTimeout !== undefined) { + clearTimeout(this.recorderTimeout) + } + } } module.exports = () => new Aperture(); diff --git a/readme.md b/readme.md index 066180b..80c7b83 100644 --- a/readme.md +++ b/readme.md @@ -113,6 +113,9 @@ Returns a `Promise` that resolves with a boolean indicating whether or not the r Returns a `Promise` for the path to the screen recording file. +#### recorder.cancel() + +Cancels a recoding if it was started ## Options Type: `object` @@ -154,6 +157,13 @@ Default: `aperture.screens()[0]` *(Primary screen)* Screen to record. +#### scaleFactor + +Type: `number`\ +Default: `1` + +The actual height and width of the capture will be multiplied by this number to create the height and width of the output. + #### audioDeviceId Type: `string`\