Skip to content

Commit

Permalink
Fix HEVC detection for Apple silicon and newer Intel processors
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 14, 2021
1 parent 7aa419e commit 42afcd2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ async function main() {
const recorder = aperture();
console.log('Screens:', await aperture.screens());
console.log('Audio devices:', await aperture.audioDevices());
console.log('Video codecs:', aperture.videoCodecs);

console.log('Preparing to record for 5 seconds');
await recorder.startRecording();
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ declare namespace aperture {
/**
Video codec to use.
The `hevc` codec requires macOS 10.13 or newer. A computer with Intel 6th generation processor or newer is strongly recommended, as otherwise it will use software encoding, which only produces 3 FPS fullscreen recording.
A computer with Intel 6th generation processor or newer is strongly recommended for the `hevc` codec, as otherwise it will use software encoding, which only produces 3 FPS fullscreen recording.
The `proRes422` and `proRes4444` codecs are uncompressed data. They will create huge files.
*/
Expand Down Expand Up @@ -110,7 +110,7 @@ declare const aperture: (() => aperture.Recorder) & {
The key is the `videoCodec` option name and the value is the codec name.
It only returns `hevc` if you're on macOS 10.13 or newer and your computer supports HEVC hardware encoding.
It only returns `hevc` if your computer supports HEVC hardware encoding.
@example
```
Expand Down
16 changes: 11 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,27 @@ const getRandomId = () => Math.random().toString(36).slice(2, 15);
const BIN = path.join(electronUtil.fixPathForAsarUnpack(__dirname), 'aperture');

const supportsHevcHardwareEncoding = (() => {
if (!macosVersion.isGreaterThanOrEqualTo('10.13')) {
return false;
const cpuModel = os.cpus()[0].model;

// All Apple silicon Macs support HEVC hardware encoding.
if (cpuModel.startsWith('Apple ')) { // Source string example: `'Apple M1'`
return true;
}

// Get the Intel Core generation, the `4` in `Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz`
// More info: https://www.intel.com/content/www/us/en/processors/processor-numbers.html
const result = /Intel.*Core.*i[57]-(\d)/.exec(os.cpus()[0].model);
// Example strings:
// - `Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz`
// - `Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz`
const result = /Intel.*Core.*i\d+-(\d)/.exec(cpuModel);

// Intel Core generation 6 or higher supports HEVC hardware encoding
return result && Number(result[1]) >= 6;
return result && Number.parseInt(result[1], 10) >= 6;
})();

class Aperture {
constructor() {
macosVersion.assertGreaterThanOrEqualTo('10.12');
macosVersion.assertGreaterThanOrEqualTo('10.13');
}

startRecording({
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Example:

#### aperture.videoCodecs -> `Map`

Get a list of available video codecs. The key is the `videoCodec` option name and the value is the codec name. It only returns `hevc` if you're on macOS 10.13 or newer and your computer supports HEVC hardware encoding.
Get a list of available video codecs. The key is the `videoCodec` option name and the value is the codec name. It only returns `hevc` if your computer supports HEVC hardware encoding.

Example:

Expand Down Expand Up @@ -167,7 +167,7 @@ Type: `string`\
Default: `'h264'`\
Values: `'hevc' | 'h264' | 'proRes422' | 'proRes4444'`

The `hevc` codec requires macOS 10.13 or newer. A computer with Intel 6th generation processor or newer is strongly recommended, as otherwise it will use software encoding, which only produces 3 FPS fullscreen recording.
A computer with Intel 6th generation processor or newer is strongly recommended for the `hevc` codec, as otherwise it will use software encoding, which only produces 3 FPS fullscreen recording.

The [`proRes422` and `proRes4444`](https://documentation.apple.com/en/finalcutpro/professionalformatsandworkflows/index.html#chapter=10%26section=2%26tasks=true) codecs are uncompressed data. They will create huge files.

Expand Down

0 comments on commit 42afcd2

Please sign in to comment.