Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scaleFactor to CLI | Add .cancel function #20

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.resolved
Expand Up @@ -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"
}
}
]
Expand Down
4 changes: 3 additions & 1 deletion Sources/ApertureCLI/record.swift
Expand Up @@ -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 {
Expand All @@ -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 = {
Expand Down
12 changes: 12 additions & 0 deletions index.d.ts
Expand Up @@ -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
Comment on lines +66 to +68
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
The 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 {
Expand Down Expand Up @@ -101,6 +108,11 @@ declare namespace aperture {
Returns a `Promise` for the path to the screen recording file.
*/
stopRecording: () => Promise<string>;

/**
Cancels a recording, if it was started
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Cancels a recording, if it was started
Cancels a recording if it was running.

*/
cancel: () => void;
}
}

Expand Down
28 changes: 23 additions & 5 deletions index.js
Expand Up @@ -39,14 +39,18 @@ class Aperture {
macosVersion.assertGreaterThanOrEqualTo('10.13');
}


recorderTimeout = undefined
Comment on lines +42 to +43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
recorderTimeout = undefined
_recorderTimeout = undefined


startRecording({
fps = 30,
cropArea = undefined,
showCursor = true,
highlightClicks = false,
screenId = 0,
audioDeviceId = undefined,
videoCodec = undefined
videoCodec = undefined,
scaleFactor = 1
} = {}) {
this.processId = getRandomId();

Expand Down Expand Up @@ -80,7 +84,8 @@ class Aperture {
showCursor,
highlightClicks,
screenId,
audioDeviceId
audioDeviceId,
scaleFactor
};

if (cropArea) {
Expand Down Expand Up @@ -123,7 +128,7 @@ class Aperture {
return this.tmpPath;
})();

const timeout = setTimeout(() => {
this.recorderTimeout = setTimeout(() => {
// `.stopRecording()` was called already
if (this.recorder === undefined) {
return;
Expand All @@ -137,7 +142,7 @@ class Aperture {
}, 5000);

this.recorder.catch(error => {
clearTimeout(timeout);
clearTimeout(recorderTimeout);
delete this.recorder;
reject(error);
});
Expand All @@ -148,7 +153,7 @@ class Aperture {
(async () => {
try {
await this.waitForEvent('onStart');
clearTimeout(timeout);
clearTimeout(recorderTimeout);
setTimeout(resolve, 1000);
} catch (error) {
reject(error);
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions readme.md
Expand Up @@ -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`
Expand Down Expand Up @@ -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`\
Expand Down