Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix: keep VP8 for macOS webcams at 1080p or below
EtienneLescotb9f9d853f14a
diff --git a/src/hooks/webcamRecorderOptions.test.ts b/src/hooks/webcamRecorderOptions.test.tsindex 0c2ffb8c8..85f9a04ea 100644--- a/src/hooks/webcamRecorderOptions.test.ts+++ b/src/hooks/webcamRecorderOptions.test.ts@@ -1,23 +1,43 @@import { describe, expect, it } from "vitest";import { webcamRecorderOptions } from "./webcamRecorderOptions";+const camera = (width: number, height: number) =>+ ({+ getVideoTracks: () => [{ getSettings: () => ({ width, height }) }],+ }) as unknown as MediaStream;+describe("webcam recorder options", () => {- it("avoids the macOS H.264 camera encoder even when it advertises support", () => {- expect(webcamRecorderOptions(null, "darwin", () => true).mimeType).toBe(+ it("avoids the macOS H.264 camera encoder at 1080p even when it advertises support", () => {+ expect(webcamRecorderOptions(camera(1920, 1080), "darwin", () => true).mimeType).toBe("video/webm;codecs=vp8",);});+ it.each([+ [2560, 1440],+ [3840, 2160],+ ])("keeps H.264 on macOS above 1080p (%ix%i), where VP8 drops frames", (width, height) => {+ expect(webcamRecorderOptions(camera(width, height), "darwin", () => true).mimeType).toBe(+ "video/webm;codecs=h264",+ );+ });++ it("keeps H.264 on macOS when the delivered size is unknown", () => {+ expect(webcamRecorderOptions(null, "darwin", () => true).mimeType).toBe(+ "video/webm;codecs=h264",+ );+ });+it.each(["win32", "linux"])("keeps H.264 preferred on %s", (platform) => {- expect(webcamRecorderOptions(null, platform, () => true).mimeType).toBe(+ expect(webcamRecorderOptions(camera(1920, 1080), platform, () => true).mimeType).toBe("video/webm;codecs=h264",);});it("negotiates another supported codec when VP8 is unavailable", () => {- expect(webcamRecorderOptions(null, "darwin", (type) => type.endsWith("vp9")).mimeType).toBe(- "video/webm;codecs=vp9",- );+ expect(+ webcamRecorderOptions(camera(1280, 720), "darwin", (type) => type.endsWith("vp9")).mimeType,+ ).toBe("video/webm;codecs=vp9");});it("lets MediaRecorder negotiate when no explicit codec is supported", () => {@@ -25,9 +45,8 @@ describe("webcam recorder options", () => {});it("uses the delivered camera dimensions for bitrate", () => {- const stream = {- getVideoTracks: () => [{ getSettings: () => ({ width: 1920, height: 1080 }) }],- } as unknown as MediaStream;- expect(webcamRecorderOptions(stream, "darwin", () => true).videoBitsPerSecond).toBe(16_000_000);+ expect(webcamRecorderOptions(camera(1920, 1080), "darwin", () => true).videoBitsPerSecond).toBe(+ 16_000_000,+ );});});diff --git a/src/hooks/webcamRecorderOptions.ts b/src/hooks/webcamRecorderOptions.tsindex 9d27db468..7c3d7d3e3 100644--- a/src/hooks/webcamRecorderOptions.ts+++ b/src/hooks/webcamRecorderOptions.ts@@ -1,5 +1,8 @@import { webcamBitrateForStream } from "./webcamCaptureTarget";+/** VP8 holds 30 fps up to this frame on Apple Silicon; at 2160p it drops ~40 % of frames. */+const MAX_VP8_PIXELS = 1920 * 1080;+/** Keep webcam encoding independent of the screen recorder's codec preference. */export function webcamRecorderOptions(stream: MediaStream | null,@@ -7,8 +10,12 @@ export function webcamRecorderOptions(isTypeSupported: (mimeType: string) => boolean = (type) => MediaRecorder.isTypeSupported(type),): MediaRecorderOptions {// Chromium's macOS H.264 camera encoder can stop delivering frames while the- // stream remains live. VP8 avoids that path; native screen capture still uses H.264.- const codecs = platform === "darwin" ? ["vp8", "vp9", "h264"] : ["h264", "vp8", "vp9"];+ // stream remains live. VP8 avoids that path, but its software encoder cannot+ // keep up above 1080p, so larger (or unknown, i.e. default 2160p) frames stay on H.264.+ const settings = stream?.getVideoTracks()[0]?.getSettings();+ const pixels = (settings?.width ?? 0) * (settings?.height ?? 0);+ const preferVp8 = platform === "darwin" && pixels > 0 && pixels <= MAX_VP8_PIXELS;+ const codecs = preferVp8 ? ["vp8", "vp9", "h264"] : ["h264", "vp8", "vp9"];const mimeType = codecs.map((codec) => `video/webm;codecs=${codec}`).find(isTypeSupported);return {...(mimeType ? { mimeType } : {}),