Create polished demo videos without editing skills. Mac/Windows/Linux
fix(export): harden native beta pipeline
wiiiii123678ece2f4aea
diff --git a/electron/electron-env.d.ts b/electron/electron-env.d.tsindex a705a9f8..c6d8b2ae 100644--- a/electron/electron-env.d.ts+++ b/electron/electron-env.d.ts@@ -284,6 +284,26 @@ interface Window {videoPath: string,options?: {startDelayMs?: number;+ browserMicrophoneProfile?: string;+ requestedBrowserMicrophoneProfile?: string | null;+ requestedConstraints?: unknown;+ mediaTrackSettings?: Record<string, boolean | number | string>;+ audioInputDevices?: Array<{+ deviceId: string;+ groupId?: string;+ label: string;+ }>;+ mediaRecorder?: {+ mimeType?: string;+ audioBitsPerSecond?: number;+ timesliceMs?: number;+ };+ chunkEvents?: Array<{+ index: number;+ size: number;+ elapsedMs: number;+ deltaMs: number | null;+ }>;},) => Promise<{ success: boolean; path?: string; error?: string }>;getRecordedVideoPath: () => Promise<{ success: boolean; path?: string; message?: string }>;@@ -361,6 +381,7 @@ interface Window {audioOptions?: {audioMode?: "none" | "copy-source" | "trim-source" | "edited-track";audioSourcePath?: string | null;+ audioSourceCodec?: string | null;audioSourceSampleRate?: number;outputDurationSec?: number;trimSegments?: Array<{ startMs: number; endMs: number }>;@@ -404,6 +425,7 @@ interface Window {options?: {audioMode?: "none" | "copy-source" | "trim-source" | "edited-track";audioSourcePath?: string | null;+ audioSourceCodec?: string | null;audioSourceSampleRate?: number;outputDurationSec?: number;trimSegments?: Array<{ startMs: number; endMs: number }>;@@ -427,6 +449,7 @@ interface Window {options?: {audioMode?: "none" | "copy-source" | "trim-source" | "edited-track";audioSourcePath?: string | null;+ audioSourceCodec?: string | null;audioSourceSampleRate?: number;outputDurationSec?: number;trimSegments?: Array<{ startMs: number; endMs: number }>;@@ -446,6 +469,7 @@ interface Window {options?: {audioMode?: "none" | "copy-source" | "trim-source" | "edited-track";audioSourcePath?: string | null;+ audioSourceCodec?: string | null;audioSourceSampleRate?: number;outputDurationSec?: number;trimSegments?: Array<{ startMs: number; endMs: number }>;@@ -783,6 +807,10 @@ interface Window {microphoneDeviceId?: string;systemAudioEnabled: boolean;}>;+ getRecordingAudioLabConfig: () => Promise<{+ browserMicrophoneProfile: string;+ requestedBrowserMicrophoneProfile: string | null;+ }>;setRecordingPreferences: (prefs: {microphoneEnabled?: boolean;microphoneDeviceId?: string;diff --git a/electron/ipc/export/native-video.test.ts b/electron/ipc/export/native-video.test.tsindex 4b022f7d..37058ea7 100644--- a/electron/ipc/export/native-video.test.ts+++ b/electron/ipc/export/native-video.test.ts@@ -50,9 +50,12 @@ import { app } from "electron";import {buildExperimentalNvidiaCudaStaticLayoutArgs,buildExperimentalWindowsGpuStaticLayoutArgs,+ buildNativeStaticLayoutSourceProxyArgs,buildNativeStaticLayoutTimelineSegments,buildNativeVideoAudioMuxArgs,+ canCopyAudioCodecIntoMp4,getExperimentalNvidiaCudaExportSkipReason,+ getNativeStaticLayoutSourceProxyBitrate,getNvidiaCudaAudioExportSkipReason,getNvidiaCudaAutoStallTimeoutMs,hasNvidiaGpuDeviceInGpuInfo,@@ -64,11 +67,16 @@ import {parseFfmpegFrameRate,parseFfmpegProgressLineSeconds,parseNativeVideoMetadataProbeOutput,+ parseNativeVideoStreamStatsProbeOutput,parseNvidiaCudaExportSummary,parseWindowsGpuExportProgressLine,parseWindowsGpuExportSummary,resolveExperimentalNvidiaCudaExportScriptPath,+ shouldCreateNativeStaticLayoutSourceProxy,+ validateNativeStaticLayoutSourceProxyMetadata,+ validateNativeVideoStreamStats,validateNvidiaCudaExportSummary,+ validateWindowsGpuExportSummary,} from "./native-video";const electronAppMock = app as unknown as {@@ -171,6 +179,92 @@ describe("normalizeNativeStaticLayoutBackground", () => {});});+describe("native static-layout source proxy", () => {+ const h264Metadata = {+ width: 1920,+ height: 1080,+ duration: 45,+ frameRate: 30,+ codec: "h264 (High)",+ hasAudio: true,+ audioCodec: "aac",+ };++ it("proxies non-H.264 codecs and non-MP4-like containers", () => {+ expect(shouldCreateNativeStaticLayoutSourceProxy(h264Metadata, "recording.mp4")).toBe(+ false,+ );+ expect(shouldCreateNativeStaticLayoutSourceProxy(h264Metadata, "recording.webm")).toBe(+ true,+ );+ expect(+ shouldCreateNativeStaticLayoutSourceProxy(+ { ...h264Metadata, codec: "vp9 (Profile 0)" },+ "recording.webm",+ ),+ ).toBe(true);+ });++ it("builds a CFR H.264 MP4 proxy at visually safe bitrate", () => {+ const options = createNvidiaCudaSkipOptions({+ inputPath: "recording.webm",+ bitrate: 22_000_000,+ durationSec: 30,+ });+ const metadata = {+ ...h264Metadata,+ codec: "vp9 (Profile 0)",+ audioCodec: "opus",+ duration: 45.036,+ streamDuration: 45.036,+ };+ const args = buildNativeStaticLayoutSourceProxyArgs(options, "source-proxy.mp4", metadata);++ expect(args).toEqual(+ expect.arrayContaining([+ "-i",+ "recording.webm",+ "-an",+ "-t",+ "45.036",+ "-c:v",+ "libx264",+ "-preset",+ "veryfast",+ "-pix_fmt",+ "yuv420p",+ "-movflags",+ "+faststart",+ "source-proxy.mp4",+ ]),+ );+ expect(args).toEqual(+ expect.arrayContaining([+ "-vf",+ "fps=fps=30:start_time=0,scale=trunc(iw/2)*2:trunc(ih/2)*2,setsar=1,format=yuv420p,setpts=PTS-STARTPTS",+ ]),+ );+ expect(getNativeStaticLayoutSourceProxyBitrate(options, metadata)).toBeGreaterThan(+ options.bitrate,+ );+ });++ it("validates proxy codec and duration before native composition", () => {+ expect(+ validateNativeStaticLayoutSourceProxyMetadata(+ { ...h264Metadata, codec: "vp9", duration: 45 },+ { sourceDurationSec: 45 },+ ),+ ).toEqual(["proxy codec is not H.264/AVC: vp9"]);+ expect(+ validateNativeStaticLayoutSourceProxyMetadata(+ { ...h264Metadata, duration: 10 },+ { sourceDurationSec: 45 },+ ),+ ).toEqual(["proxy duration 10.000s shorter than expected 45.000s"]);+ });+});+describe("getNvidiaCudaAudioExportSkipReason", () => {it("allows video-only CUDA exports by default", () => {withNvidiaCudaAudioOverride(undefined, () => {@@ -458,6 +552,18 @@ describe("buildExperimentalNvidiaCudaStaticLayoutArgs", () => {expect(args).toEqual(expect.arrayContaining(["--background-blur", "36"]));});+ it("passes the export encoding mode to the CUDA wrapper", () => {+ const args = buildExperimentalNvidiaCudaStaticLayoutArgs(+ createNvidiaCudaSkipOptions({+ encodingMode: "quality",+ }),+ "output.mp4",+ "work",+ );++ expect(args).toEqual(expect.arrayContaining(["--encoding-mode", "quality"]));+ });+it("passes webcam source-time controls to the CUDA wrapper", () => {const args = buildExperimentalNvidiaCudaStaticLayoutArgs(createNvidiaCudaSkipOptions({@@ -584,6 +690,7 @@ describe("buildNativeVideoAudioMuxArgs", () => {it("stream-copies source audio and preserves the requested video duration", () => {const args = buildNativeVideoAudioMuxArgs("video.mp4", "source.mp4", "out.mp4", {audioMode: "copy-source",+ audioSourceCodec: "aac (LC) (mp4a / 0x6134706D)",outputDurationSec: 60,});@@ -607,12 +714,24 @@ describe("buildNativeVideoAudioMuxArgs", () => {it("does not shorten copy-source muxes when no explicit duration is available", () => {const args = buildNativeVideoAudioMuxArgs("video.mp4", "source.mp4", "out.mp4", {audioMode: "copy-source",+ audioSourceCodec: "aac",});expect(args).toEqual(expect.arrayContaining(["-c:a", "copy"]));expect(args).not.toContain("-shortest");});+ it("transcodes WebM/Opus source audio when muxing into MP4", () => {+ const args = buildNativeVideoAudioMuxArgs("video.mp4", "source.webm", "out.mp4", {+ audioMode: "copy-source",+ audioSourceCodec: "opus",+ outputDurationSec: 60,+ });++ expect(args).toEqual(expect.arrayContaining(["-c:a", "aac", "-b:a", "192k"]));+ expect(args.join(";")).not.toContain("-c:a;copy");+ });+it("keeps filtered audio on the AAC encode path", () => {const args = buildNativeVideoAudioMuxArgs("video.mp4", "source.mp4", "out.mp4", {audioMode: "trim-source",@@ -644,7 +763,7 @@ describe("buildNativeVideoAudioMuxArgs", () => {"video.mp4","source.mp4","out.mp4",- { audioMode: "copy-source", outputDurationSec: 60 },+ { audioMode: "copy-source", audioSourceCodec: "aac", outputDurationSec: 60 },{ progressPipe: 2 },);@@ -654,6 +773,62 @@ describe("buildNativeVideoAudioMuxArgs", () => {});});+describe("canCopyAudioCodecIntoMp4", () => {+ it("allows common MP4-compatible audio codecs", () => {+ expect(canCopyAudioCodecIntoMp4("aac (LC) (mp4a / 0x6134706D)")).toBe(true);+ expect(canCopyAudioCodecIntoMp4("mp3")).toBe(true);+ });++ it("blocks Opus so native exports transcode it to AAC for MP4", () => {+ expect(canCopyAudioCodecIntoMp4("opus")).toBe(false);+ });+});++describe("validateNativeVideoStreamStats", () => {+ it("accepts a complete video stream", () => {+ expect(+ validateNativeVideoStreamStats(+ { durationSec: 45, frameCount: 1350, frameRate: 30 },+ { durationSec: 45, targetFrames: 1350 },+ ),+ ).toEqual([]);+ });++ it("rejects files with container duration but too few video frames", () => {+ expect(+ validateNativeVideoStreamStats(+ { durationSec: 0.067, frameCount: 2, frameRate: 30 },+ { durationSec: 45, targetFrames: 1350 },+ ),+ ).toEqual([+ "video frames 2 below expected minimum 1282",+ "video stream duration 0.067s differs from expected 45.000s",+ ]);+ });+});++describe("parseNativeVideoStreamStatsProbeOutput", () => {+ it("parses FFprobe count-frame JSON output", () => {+ expect(+ parseNativeVideoStreamStatsProbeOutput(+ JSON.stringify({+ streams: [+ {+ duration: "44.999000",+ nb_read_frames: "1349",+ avg_frame_rate: "30000/1001",+ },+ ],+ }),+ ),+ ).toEqual({+ durationSec: 44.999,+ frameCount: 1349,+ frameRate: 30000 / 1001,+ });+ });+});+describe("parseFfmpegProgressLineSeconds", () => {it("parses FFmpeg progress timestamps into seconds", () => {expect(parseFfmpegProgressLineSeconds("out_time_us=1500000")).toBe(1.5);@@ -692,6 +867,29 @@ describe("parseWindowsGpuExportSummary", () => {});});+describe("validateWindowsGpuExportSummary", () => {+ it("rejects short Windows GPU outputs before muxing audio", () => {+ expect(+ validateWindowsGpuExportSummary(+ { success: true, frames: 2, seconds: 0.067 },+ { durationSec: 45, targetFrames: 1350 },+ ),+ ).toEqual([+ "Windows GPU frames 2 below expected minimum 1282",+ "Windows GPU duration 0.067s differs from expected 45.000s",+ ]);+ });++ it("accepts complete Windows GPU outputs within tolerance", () => {+ expect(+ validateWindowsGpuExportSummary(+ { success: true, frames: 1345, seconds: 44.9 },+ { durationSec: 45, targetFrames: 1350 },+ ),+ ).toEqual([]);+ });+});+describe("parseNvidiaCudaExportSummary", () => {it("parses the pretty JSON summary emitted by the CUDA wrapper", () => {const summary = parseNvidiaCudaExportSummary(diff --git a/electron/ipc/export/native-video.ts b/electron/ipc/export/native-video.tsindex 661f4aa1..bac98c42 100644--- a/electron/ipc/export/native-video.ts+++ b/electron/ipc/export/native-video.ts@@ -48,6 +48,10 @@ const NVIDIA_CUDA_ALLOW_AUDIO_EXPORT_ENV = "RECORDLY_NVIDIA_CUDA_ALLOW_AUDIO_EXPconst NVIDIA_CUDA_FORCE_VIDEO_ONLY_ENV = "RECORDLY_NVIDIA_CUDA_FORCE_VIDEO_ONLY";const NVIDIA_CUDA_AUTO_STALL_TIMEOUT_ENV = "RECORDLY_NVIDIA_CUDA_AUTO_STALL_TIMEOUT_MS";const DEFAULT_NVIDIA_CUDA_AUTO_STALL_TIMEOUT_MS = 120_000;+const NATIVE_STATIC_LAYOUT_SOURCE_PROXY_REFERENCE_PIXEL_RATE = 1920 * 1080 * 30;+const NATIVE_STATIC_LAYOUT_SOURCE_PROXY_1080P30_BITRATE = 24_000_000;+const NATIVE_STATIC_LAYOUT_SOURCE_PROXY_MAX_BITRATE = 80_000_000;+const NATIVE_STATIC_LAYOUT_SOURCE_PROXY_CONTAINERS = new Set([".mp4", ".m4v", ".mov"]);type ElectronGpuDeviceLike = {vendorId?: number | string;@@ -286,6 +290,12 @@ export interface NativeVideoMetadataProbe {audioSampleRate?: number;}+export interface NativeVideoStreamStatsProbe {+ durationSec: number | null;+ frameCount: number | null;+ frameRate: number | null;+}+export interface NativeStaticLayoutChunkMetric {index: number;startSec: number;@@ -450,6 +460,130 @@ export function validateNvidiaCudaExportSummary(return issues;}+export function validateWindowsGpuExportSummary(+ summary: WindowsGpuExportSummary,+ expected: {+ durationSec: number;+ targetFrames: number;+ },+) {+ const issues: string[] = [];+ const expectedFrames = Math.max(1, Math.round(expected.targetFrames));+ const minimumFrames = Math.max(1, Math.floor(expectedFrames * 0.95));+ const expectedDurationSec = Math.max(0, expected.durationSec);+ const durationToleranceSec = Math.min(2, Math.max(0.5, expectedDurationSec * 0.02));+ const frames = getFiniteNumber(summary.frames);+ const mediaMs = getFiniteNumber(summary.mediaMs);+ const seconds = getFiniteNumber(summary.seconds) ?? (mediaMs !== null ? mediaMs / 1000 : null);++ if (frames === null) {+ issues.push("missing Windows GPU frame count");+ } else if (frames < minimumFrames) {+ issues.push(`Windows GPU frames ${frames} below expected minimum ${minimumFrames}`);+ }+ if (+ seconds !== null &&+ Number.isFinite(seconds) &&+ Math.abs(seconds - expectedDurationSec) > durationToleranceSec+ ) {+ issues.push(+ `Windows GPU duration ${seconds.toFixed(3)}s differs from expected ${expectedDurationSec.toFixed(3)}s`,+ );+ }++ return issues;+}++function parseRationalFrameRate(value: unknown) {+ if (typeof value !== "string") {+ return null;+ }+ const [numeratorRaw, denominatorRaw] = value.split("/");+ const numerator = Number(numeratorRaw);+ const denominator = Number(denominatorRaw);+ if (+ !Number.isFinite(numerator) ||+ !Number.isFinite(denominator) ||+ numerator <= 0 ||+ denominator <= 0+ ) {+ return null;+ }++ return numerator / denominator;+}++function parseOptionalPositiveNumber(value: unknown) {+ const parsed =+ typeof value === "number" ? value : typeof value === "string" ? Number(value) : NaN;+ return Number.isFinite(parsed) && parsed > 0 ? parsed : null;+}++function parseOptionalPositiveInteger(value: unknown) {+ const parsed = parseOptionalPositiveNumber(value);+ return parsed === null ? null : Math.max(0, Math.round(parsed));+}++export function parseNativeVideoStreamStatsProbeOutput(+ output: string,+): NativeVideoStreamStatsProbe | null {+ const parsed = JSON.parse(output) as {+ streams?: Array<{+ duration?: unknown;+ nb_frames?: unknown;+ nb_read_frames?: unknown;+ avg_frame_rate?: unknown;+ r_frame_rate?: unknown;+ }>;+ };+ const stream = parsed.streams?.[0];+ if (!stream) {+ return null;+ }++ return {+ durationSec: parseOptionalPositiveNumber(stream.duration),+ frameCount:+ parseOptionalPositiveInteger(stream.nb_read_frames) ??+ parseOptionalPositiveInteger(stream.nb_frames),+ frameRate:+ parseRationalFrameRate(stream.avg_frame_rate) ??+ parseRationalFrameRate(stream.r_frame_rate),+ };+}++export function validateNativeVideoStreamStats(+ stats: NativeVideoStreamStatsProbe,+ expected: {+ durationSec: number;+ targetFrames: number;+ },+) {+ const issues: string[] = [];+ const expectedFrames = Math.max(1, Math.round(expected.targetFrames));+ const minimumFrames = Math.max(1, Math.floor(expectedFrames * 0.95));+ const expectedDurationSec = Math.max(0, expected.durationSec);+ const durationToleranceSec = Math.min(2, Math.max(0.5, expectedDurationSec * 0.02));++ if (stats.frameCount === null) {+ issues.push("missing video frame count");+ } else if (stats.frameCount < minimumFrames) {+ issues.push(`video frames ${stats.frameCount} below expected minimum ${minimumFrames}`);+ }++ if (stats.durationSec === null) {+ issues.push("missing video stream duration");+ } else if (Math.abs(stats.durationSec - expectedDurationSec) > durationToleranceSec) {+ issues.push(+ `video stream duration ${stats.durationSec.toFixed(+ 3,+ )}s differs from expected ${expectedDurationSec.toFixed(3)}s`,+ );+ }++ return issues;+}+function isNvidiaCudaTimestampAlignedSummary(summary: NvidiaCudaExportSummary) {const nativeSummary = summary.nativeSummary;const timelineFields = [@@ -802,6 +936,158 @@ export async function probeNativeVideoMetadata(return metadata;}+export async function probeNativeVideoStreamStats(+ ffprobePath: string,+ inputPath: string,+): Promise<NativeVideoStreamStatsProbe> {+ const result = await execFileAsync(+ ffprobePath,+ [+ "-v",+ "error",+ "-select_streams",+ "v:0",+ "-count_frames",+ "-show_entries",+ "stream=duration,nb_frames,nb_read_frames,avg_frame_rate,r_frame_rate",+ "-of",+ "json",+ inputPath,+ ],+ { timeout: 120_000, maxBuffer: 2 * 1024 * 1024 },+ );+ const stats = parseNativeVideoStreamStatsProbeOutput(result.stdout);+ if (!stats) {+ throw new Error("Unable to parse native video stream stats from FFprobe output");+ }++ return stats;+}++async function validateNativeVideoOutputFile(+ ffprobePath: string,+ videoPath: string,+ expected: {+ durationSec: number;+ targetFrames: number;+ },+) {+ const stats = await probeNativeVideoStreamStats(ffprobePath, videoPath);+ const issues = validateNativeVideoStreamStats(stats, expected);+ if (issues.length > 0) {+ throw new Error(`Native video output is invalid: ${issues.join("; ")}`);+ }+}++export function isNativeStaticLayoutH264SourceCodec(codec: string | undefined) {+ const normalized = (codec ?? "").trim().toLowerCase();+ return (+ /\bh\.?264\b/.test(normalized) ||+ normalized.includes("avc1") ||+ normalized.includes("avc3") ||+ normalized.includes("mpeg-4 avc")+ );+}++export function shouldCreateNativeStaticLayoutSourceProxy(+ metadata: Pick<NativeVideoMetadataProbe, "codec">,+ inputPath: string,+) {+ const extension = path.extname(inputPath).toLowerCase();+ return (+ !isNativeStaticLayoutH264SourceCodec(metadata.codec) ||+ !NATIVE_STATIC_LAYOUT_SOURCE_PROXY_CONTAINERS.has(extension)+ );+}++export function getNativeStaticLayoutSourceProxyBitrate(+ options: Pick<NativeStaticLayoutExportOptions, "bitrate" | "frameRate" | "width" | "height">,+ metadata?: Pick<NativeVideoMetadataProbe, "width" | "height">,+) {+ const frameRate = Math.max(1, Math.round(options.frameRate));+ const width = Math.max(1, Math.round(metadata?.width ?? options.width));+ const height = Math.max(1, Math.round(metadata?.height ?? options.height));+ const pixelRateScale = Math.sqrt(+ (width * height * frameRate) / NATIVE_STATIC_LAYOUT_SOURCE_PROXY_REFERENCE_PIXEL_RATE,+ );+ const qualityFloor = Math.round(+ NATIVE_STATIC_LAYOUT_SOURCE_PROXY_1080P30_BITRATE * pixelRateScale,+ );+ return Math.min(+ NATIVE_STATIC_LAYOUT_SOURCE_PROXY_MAX_BITRATE,+ Math.max(Math.round(options.bitrate * 1.2), qualityFloor),+ );+}++export function buildNativeStaticLayoutSourceProxyArgs(+ options: NativeStaticLayoutExportOptions,+ outputPath: string,+ metadata: NativeVideoMetadataProbe,+) {+ const frameRate = Math.max(1, Math.round(options.frameRate));+ const sourceDurationSec = Math.max(+ 0.001,+ metadata.streamDuration ?? metadata.duration ?? options.durationSec,+ );+ const proxyBitrate = getNativeStaticLayoutSourceProxyBitrate(options, metadata);+ return [+ "-y",+ "-hide_banner",+ "-loglevel",+ "error",+ "-i",+ options.inputPath,+ "-map",+ "0:v:0",+ "-an",+ "-t",+ formatCliNumber(sourceDurationSec),+ "-vf",+ `fps=fps=${frameRate}:start_time=0,scale=trunc(iw/2)*2:trunc(ih/2)*2,setsar=1,format=yuv420p,setpts=PTS-STARTPTS`,+ "-c:v",+ "libx264",+ "-preset",+ "veryfast",+ "-tune",+ "zerolatency",+ "-g",+ String(Math.max(1, Math.round(frameRate * 2))),+ "-b:v",+ String(proxyBitrate),+ "-maxrate",+ String(Math.round(proxyBitrate * 1.25)),+ "-bufsize",+ String(proxyBitrate * 2),+ "-pix_fmt",+ "yuv420p",+ "-movflags",+ "+faststart",+ outputPath,+ ];+}++export function validateNativeStaticLayoutSourceProxyMetadata(+ metadata: NativeVideoMetadataProbe,+ expected: { sourceDurationSec: number },+) {+ const issues: string[] = [];+ const expectedDurationSec = Math.max(0, expected.sourceDurationSec);+ const durationToleranceSec = Math.min(2, Math.max(0.5, expectedDurationSec * 0.03));+ if (!isNativeStaticLayoutH264SourceCodec(metadata.codec)) {+ issues.push(`proxy codec is not H.264/AVC: ${metadata.codec || "unknown"}`);+ }+ if (!Number.isFinite(metadata.duration) || metadata.duration <= 0) {+ issues.push("proxy duration is unavailable");+ } else if (metadata.duration + durationToleranceSec < expectedDurationSec) {+ issues.push(+ `proxy duration ${metadata.duration.toFixed(+ 3,+ )}s shorter than expected ${expectedDurationSec.toFixed(3)}s`,+ );+ }+ return issues;+}+export function getNativeVideoExportMaxQueuedWriteBytes(inputByteSize: number) {if (inputByteSize === 0) return 8 * 1024 * 1024;return Math.min(64 * 1024 * 1024, Math.max(16 * 1024 * 1024, inputByteSize * 4));@@ -2106,6 +2392,53 @@ async function prepareWindowsGpuWebcamInput(return { inputPath: outputPath, elapsedMs: result.elapsedMs };}+async function prepareNativeStaticLayoutSourceInput(+ ffmpegPath: string,+ options: NativeStaticLayoutExportOptions,+ outputPath: string,+ session: NativeStaticLayoutExportSession,+) {+ const metadata = await probeNativeVideoMetadata(ffmpegPath, options.inputPath);+ if (!shouldCreateNativeStaticLayoutSourceProxy(metadata, options.inputPath)) {+ return {+ inputPath: options.inputPath,+ elapsedMs: 0,+ sourceCodec: metadata.codec,+ proxyCreated: false,+ };+ }++ const sourceDurationSec = Math.max(+ 0.001,+ metadata.streamDuration ?? metadata.duration ?? options.durationSec,+ );+ const result = await runFfmpegWithMetrics(+ ffmpegPath,+ buildNativeStaticLayoutSourceProxyArgs(options, outputPath, metadata),+ Math.max(5 * 60 * 1000, sourceDurationSec * 2000),+ session,+ );+ if (!result.success) {+ throw new Error(getFfmpegFailureMessage(result));+ }++ const proxyMetadata = await probeNativeVideoMetadata(ffmpegPath, outputPath);+ const validationIssues = validateNativeStaticLayoutSourceProxyMetadata(proxyMetadata, {+ sourceDurationSec,+ });+ if (validationIssues.length > 0) {+ throw new Error(`Native source proxy is invalid: ${validationIssues.join("; ")}`);+ }++ return {+ inputPath: outputPath,+ elapsedMs: result.elapsedMs,+ sourceCodec: metadata.codec,+ proxyCodec: proxyMetadata.codec,+ proxyCreated: true,+ };+}+export function buildExperimentalNvidiaCudaStaticLayoutArgs(options: NativeStaticLayoutExportOptions,outputPath: string,@@ -2127,6 +2460,8 @@ export function buildExperimentalNvidiaCudaStaticLayoutArgs(String(Math.max(1, Math.round(options.frameRate))),"--bitrate-mbps",String(getNvidiaCudaBitrateMbps(options)),+ "--encoding-mode",+ options.encodingMode,"--duration-sec",formatCliNumber(options.durationSec),"--stream-sync",@@ -2591,7 +2926,9 @@ export async function exportNativeStaticLayoutVideo(const chunkDirectory = path.join(app.getPath("temp"), sessionId);const concatListPath = path.join(chunkDirectory, "chunks.txt");const videoOnlyPath = path.join(app.getPath("temp"), `${sessionId}.mp4`);+ const ffprobePath = getFfprobeBinaryPath();let outputPathToKeep: string | null = null;+ let videoOutputValidated = false;const metrics: NativeStaticLayoutExportMetrics = {chunkCount: chunks.length,chunkDurationSec,@@ -2599,10 +2936,37 @@ export async function exportNativeStaticLayoutVideo(fallbackChunkCount: 0,chunks: [],};+ const validateRenderedVideoOutput = async () => {+ await validateNativeVideoOutputFile(ffprobePath, videoOnlyPath, {+ durationSec: options.durationSec,+ targetFrames: Math.ceil(options.durationSec * options.frameRate),+ });+ videoOutputValidated = true;+ };try {nativeStaticLayoutExportSessions.set(sessionId, session);await fs.mkdir(chunkDirectory, { recursive: true });+ const sourceInput = await prepareNativeStaticLayoutSourceInput(+ ffmpegPath,+ options,+ path.join(chunkDirectory, "source-proxy.mp4"),+ session,+ );+ if (sourceInput.elapsedMs > 0) {+ metrics.staticAssetExecMs = (metrics.staticAssetExecMs ?? 0) + sourceInput.elapsedMs;+ }+ if (sourceInput.inputPath !== options.inputPath) {+ console.info("[native-static-layout-export] Prepared H.264 source proxy", {+ sourceCodec: sourceInput.sourceCodec,+ proxyCodec: sourceInput.proxyCodec,+ elapsedMs: sourceInput.elapsedMs,+ });+ options = {+ ...options,+ inputPath: sourceInput.inputPath,+ };+ }const timelineMapPath = await prepareNativeStaticLayoutTimelineMap(options,path.join(chunkDirectory, "timeline-map.csv"),@@ -2799,6 +3163,7 @@ export async function exportNativeStaticLayoutVideo("Experimental NVIDIA CUDA compositor produced an empty output file",);}+ await validateRenderedVideoOutput();console.info("[native-static-layout-export] NVIDIA CUDA compositor completed",{@@ -2864,6 +3229,16 @@ export async function exportNativeStaticLayoutVideo(session,onProgress,);+ const gpuValidationIssues = validateWindowsGpuExportSummary(gpuResult.summary, {+ durationSec: options.durationSec,+ targetFrames: Math.ceil(options.durationSec * options.frameRate),+ });+ if (gpuValidationIssues.length > 0) {+ throw new Error(+ `Experimental Windows GPU compositor produced an invalid output: ${gpuValidationIssues.join("; ")}`,+ );+ }+ await validateRenderedVideoOutput();console.info("[native-static-layout-export] Windows GPU compositor completed", {elapsedMs: gpuResult.elapsedMs,width: gpuResult.summary.width,@@ -3106,6 +3481,9 @@ export async function exportNativeStaticLayoutVideo(const videoOnlyStat = await fs.stat(videoOnlyPath);metrics.videoOnlyBytes = videoOnlyStat.size;+ if (!videoOutputValidated) {+ await validateRenderedVideoOutput();+ }if (didMuxAudioInline) {outputPathToKeep = videoOnlyPath;return {@@ -3267,6 +3645,21 @@ export async function resolveNativeVideoEncoder(throw new Error("No usable FFmpeg encoder was available for native export");}+export function canCopyAudioCodecIntoMp4(codec?: string | null) {+ const normalized = (codec ?? "").trim().toLowerCase();+ if (!normalized) {+ return true;+ }++ return (+ normalized.includes("aac") ||+ normalized.includes("mp4a") ||+ normalized.includes("mpeg-4 audio") ||+ normalized.includes("mp3") ||+ normalized.includes("alac")+ );+}+export function buildNativeVideoAudioMuxArgs(videoPath: string,audioInputPath: string,@@ -3326,7 +3719,7 @@ export function buildNativeVideoAudioMuxArgs(}args.push("-c:v", "copy");- if (audioMode === "copy-source") {+ if (audioMode === "copy-source" && canCopyAudioCodecIntoMp4(options.audioSourceCodec)) {args.push("-c:a", "copy");} else {args.push("-c:a", "aac", "-b:a", "192k");diff --git a/electron/ipc/nativeVideoExport.ts b/electron/ipc/nativeVideoExport.tsindex 21eb12fd..1bd41815 100644--- a/electron/ipc/nativeVideoExport.ts+++ b/electron/ipc/nativeVideoExport.ts@@ -37,6 +37,7 @@ export interface NativeVideoExportEditedTrackSegment extends NativeVideoExportAuexport interface NativeVideoExportFinishOptions {audioMode?: NativeVideoExportAudioMode;audioSourcePath?: string | null;+ audioSourceCodec?: string | null;audioSourceSampleRate?: number;outputDurationSec?: number;trimSegments?: NativeVideoExportAudioSegment[];diff --git a/electron/ipc/recording/audioFilters.test.ts b/electron/ipc/recording/audioFilters.test.tsindex 0436bb4d..1e80e266 100644--- a/electron/ipc/recording/audioFilters.test.ts+++ b/electron/ipc/recording/audioFilters.test.ts@@ -1,6 +1,9 @@import { describe, expect, it } from "vitest";import {+ BROWSER_MIC_SIDECAR_FILTERS,+ BROWSER_MIC_SIDECAR_NO_AGC_GAIN_FILTERS,+ getBrowserMicSidecarFilters,RECORDING_AUDIO_SIDECAR_DEBUG_ENV,shouldKeepRecordingAudioSidecars,WINDOWS_NATIVE_MIC_PRE_FILTERS,@@ -35,3 +38,37 @@ describe("Windows native mic pre-filter policy", () => {).toBe(false);});});++describe("browser microphone sidecar post-processing", () => {+ it("keeps the browser fallback chain conservative and speech-oriented", () => {+ expect(BROWSER_MIC_SIDECAR_FILTERS).toEqual([+ "adeclip=threshold=1",+ "adeclick=w=40:o=75:t=3:b=2",+ "highpass=f=85",+ "lowpass=f=9500",+ "afftdn=nr=10:nf=-45:tn=1",+ "alimiter=limit=0.92:level=0",+ ]);+ expect(+ BROWSER_MIC_SIDECAR_FILTERS.some((filter) =>+ /(^|,)(loudnorm|dynaudnorm|volume)=/i.test(filter),+ ),+ ).toBe(false);+ });++ it("adds bounded speech gain only for the no-AGC browser mic profile", () => {+ expect(getBrowserMicSidecarFilters("processed")).toEqual(BROWSER_MIC_SIDECAR_FILTERS);+ expect(getBrowserMicSidecarFilters("no-agc")).toEqual([+ "adeclip=threshold=1",+ "adeclick=w=40:o=75:t=3:b=2",+ "highpass=f=85",+ "lowpass=f=9500",+ "afftdn=nr=10:nf=-45:tn=1",+ ...BROWSER_MIC_SIDECAR_NO_AGC_GAIN_FILTERS,+ ]);+ expect(BROWSER_MIC_SIDECAR_NO_AGC_GAIN_FILTERS).toContain(+ "speechnorm=p=0.92:e=12:c=2:r=0.0005:f=0.001",+ );+ expect(BROWSER_MIC_SIDECAR_NO_AGC_GAIN_FILTERS).toContain("alimiter=limit=0.92:level=0");+ });+});diff --git a/electron/ipc/recording/audioFilters.ts b/electron/ipc/recording/audioFilters.tsindex 72bc3915..5da2a29e 100644--- a/electron/ipc/recording/audioFilters.ts+++ b/electron/ipc/recording/audioFilters.ts@@ -2,6 +2,36 @@// amplified wireless-headset noise and WASAPI discontinuities during beta tests.export const WINDOWS_NATIVE_MIC_PRE_FILTERS = ["adeclip=threshold=1"];+// Browser mic fallback uses Chromium/WebRTC voice processing, but beta tests+// showed its realtime AGC can introduce short crackle bursts on some Realtek+// and headset paths. Default to no AGC, then restore usable level offline with+// bounded speech expansion and a limiter.+export const BROWSER_MIC_SIDECAR_BASE_FILTERS = [+ "adeclip=threshold=1",+ "adeclick=w=40:o=75:t=3:b=2",+ "highpass=f=85",+ "lowpass=f=9500",+ "afftdn=nr=10:nf=-45:tn=1",+];++export const BROWSER_MIC_SIDECAR_NO_AGC_GAIN_FILTERS = [+ "speechnorm=p=0.92:e=12:c=2:r=0.0005:f=0.001",+ "alimiter=limit=0.92:level=0",+];++export const BROWSER_MIC_SIDECAR_FILTERS = [+ ...BROWSER_MIC_SIDECAR_BASE_FILTERS,+ "alimiter=limit=0.92:level=0",+];++export function getBrowserMicSidecarFilters(profile?: string | null) {+ if (profile === "no-agc") {+ return [...BROWSER_MIC_SIDECAR_BASE_FILTERS, ...BROWSER_MIC_SIDECAR_NO_AGC_GAIN_FILTERS];+ }++ return BROWSER_MIC_SIDECAR_FILTERS;+}+export const RECORDING_AUDIO_SIDECAR_DEBUG_ENV = "RECORDLY_KEEP_RECORDING_AUDIO_SIDECARS";export function shouldKeepRecordingAudioSidecars(env: NodeJS.ProcessEnv = process.env) {diff --git a/electron/ipc/recording/diagnostics.test.ts b/electron/ipc/recording/diagnostics.test.tsindex 87c16b1f..903c7722 100644--- a/electron/ipc/recording/diagnostics.test.ts+++ b/electron/ipc/recording/diagnostics.test.ts@@ -54,6 +54,7 @@ describe("getCompanionAudioFallbackPaths", () => {}));vi.doMock("../ffmpeg/binary", () => ({getFfmpegBinaryPath: () => "ffmpeg",+ getFfprobeBinaryPath: () => "ffprobe",}));});@@ -177,6 +178,120 @@ describe("getCompanionAudioFallbackPaths", () => {);});+ it("uses video stream frames when container duration is misleading", async () => {+ const { parseFfprobeVideoStreamDuration } = await import("./diagnostics");++ expect(+ parseFfprobeVideoStreamDuration(+ JSON.stringify({+ streams: [+ {+ duration: "18.000000",+ nb_read_frames: "540",+ avg_frame_rate: "30/1",+ },+ ],+ }),+ ),+ ).toEqual({+ durationSeconds: 18,+ frameCount: 540,+ frameRate: 30,+ });+ });++ it("derives video stream duration from frame count when stream duration is absent", async () => {+ const { parseFfprobeVideoStreamDuration } = await import("./diagnostics");++ expect(+ parseFfprobeVideoStreamDuration(+ JSON.stringify({+ streams: [+ {+ nb_read_frames: "540",+ avg_frame_rate: "30/1",+ },+ ],+ }),+ ),+ ).toEqual({+ durationSeconds: 18,+ frameCount: 540,+ frameRate: 30,+ });+ });++ it("writes a recording diagnostics sidecar with stream and audio probes", async () => {+ const videoPath = path.join(tempRoot, "recording-123.mp4");+ const micPath = path.join(tempRoot, "recording-123.mic.wav");+ await Promise.all([+ fs.writeFile(videoPath, "video"),+ fs.writeFile(micPath, "mic"),+ fs.writeFile(`${micPath}.json`, JSON.stringify({ startDelayMs: 125 })),+ ]);++ execFileMock.mockImplementation(+ (+ file: string,+ args: string[],+ _options: Record<string, unknown>,+ callback: ExecFileCallback,+ ) => {+ if (file === "ffprobe" || args.includes("-of")) {+ callback(+ null,+ JSON.stringify({+ streams: [+ {+ duration: "18.000000",+ nb_read_frames: "540",+ avg_frame_rate: "30/1",+ },+ ],+ }),+ "",+ );+ return;+ }++ const error = new Error("ffmpeg probe") as Error & { stderr?: string };+ error.stderr = "Duration: 00:00:18.00, start: 0.000000";+ callback(error, "", error.stderr);+ },+ );++ const { getRecordingDiagnosticsPath, writeRecordingDiagnosticsSnapshot } = await import(+ "./diagnostics"+ );++ const diagnosticsPath = await writeRecordingDiagnosticsSnapshot(videoPath, {+ backend: "windows-wgc",+ phase: "mux-start",+ expectedDurationMs: 60_000,+ outputPath: videoPath,+ microphonePath: micPath,+ details: {+ hasMicrophone: true,+ },+ });+ const diagnostics = JSON.parse(await fs.readFile(diagnosticsPath, "utf8"));++ expect(diagnosticsPath).toBe(getRecordingDiagnosticsPath(videoPath));+ expect(diagnostics.events).toHaveLength(1);+ expect(diagnostics.latest.expectedDurationMs).toBe(60_000);+ expect(diagnostics.latest.media.video.stream).toEqual({+ durationSeconds: 18,+ frameCount: 540,+ frameRate: 30,+ });+ expect(diagnostics.latest.media.microphone).toMatchObject({+ path: micPath,+ exists: true,+ containerDurationSeconds: 18,+ startDelayMs: 125,+ });+ });+it("ignores invalid sidecar timing metadata values", async () => {const micPath = path.join(tempRoot, "recording.mic.wav");await Promise.all([diff --git a/electron/ipc/recording/diagnostics.ts b/electron/ipc/recording/diagnostics.tsindex b445d704..081e2412 100644--- a/electron/ipc/recording/diagnostics.ts+++ b/electron/ipc/recording/diagnostics.ts@@ -2,7 +2,7 @@ import { execFile } from "node:child_process";import fs from "node:fs/promises";import { promisify } from "node:util";import { COMPANION_AUDIO_LAYOUTS } from "../constants";-import { getFfmpegBinaryPath } from "../ffmpeg/binary";+import { getFfmpegBinaryPath, getFfprobeBinaryPath } from "../ffmpeg/binary";import { lastNativeCaptureDiagnostics, setLastNativeCaptureDiagnostics } from "../state";import type { CompanionAudioCandidate, NativeCaptureDiagnostics } from "../types";import { parseJsonWithByteOrderMark } from "../utils";@@ -16,6 +16,40 @@ type CompanionAudioTimingMetadata = {startDelayMs?: number;};+export type VideoStreamDurationProbe = {+ durationSeconds: number | null;+ frameCount: number | null;+ frameRate: number | null;+};++export type RecordingDiagnosticsSnapshot = {+ backend: NativeCaptureDiagnostics["backend"];+ phase:+ | `${NativeCaptureDiagnostics["phase"]}`+ | "pad"+ | "mic-sidecar"+ | "mux-start"+ | "mux-complete"+ | "mux-error";+ expectedDurationMs?: number | null;+ outputPath?: string | null;+ systemAudioPath?: string | null;+ microphonePath?: string | null;+ processOutput?: string;+ error?: string;+ details?: Record<string, unknown>;+};++type RecordingDiagnosticsLog = {+ version: 1;+ createdAt: string;+ updatedAt: string;+ videoPath: string;+ diagnosticsPath: string;+ events: unknown[];+ latest?: unknown;+};+export function recordNativeCaptureDiagnostics(diagnostics: Omit<NativeCaptureDiagnostics, "timestamp">,) {@@ -83,6 +117,210 @@ export async function probeMediaDurationSeconds(filePath: string): Promise<numbereturn 0;}+function parsePositiveNumber(value: unknown) {+ const parsed =+ typeof value === "number" ? value : typeof value === "string" ? Number(value) : NaN;+ return Number.isFinite(parsed) && parsed > 0 ? parsed : null;+}++function parsePositiveInteger(value: unknown) {+ const parsed = parsePositiveNumber(value);+ return parsed === null ? null : Math.max(0, Math.round(parsed));+}++function parseFrameRate(value: unknown) {+ if (typeof value !== "string") {+ return null;+ }+ const [numeratorRaw, denominatorRaw] = value.split("/");+ const numerator = Number(numeratorRaw);+ const denominator = Number(denominatorRaw);+ if (+ !Number.isFinite(numerator) ||+ !Number.isFinite(denominator) ||+ numerator <= 0 ||+ denominator <= 0+ ) {+ return null;+ }++ return numerator / denominator;+}++export function parseFfprobeVideoStreamDuration(output: string): VideoStreamDurationProbe | null {+ const parsed = JSON.parse(output) as {+ streams?: Array<{+ duration?: unknown;+ nb_frames?: unknown;+ nb_read_frames?: unknown;+ avg_frame_rate?: unknown;+ r_frame_rate?: unknown;+ }>;+ };+ const stream = parsed.streams?.[0];+ if (!stream) {+ return null;+ }++ const frameRate = parseFrameRate(stream.avg_frame_rate) ?? parseFrameRate(stream.r_frame_rate);+ const frameCount =+ parsePositiveInteger(stream.nb_read_frames) ?? parsePositiveInteger(stream.nb_frames);+ const streamDuration = parsePositiveNumber(stream.duration);+ const frameDerivedDuration =+ frameCount !== null && frameRate !== null && frameRate > 0 ? frameCount / frameRate : null;++ return {+ durationSeconds: streamDuration ?? frameDerivedDuration,+ frameCount,+ frameRate,+ };+}++export async function probeVideoStreamDuration(+ filePath: string,+): Promise<VideoStreamDurationProbe | null> {+ try {+ const result = await execFileAsync(+ getFfprobeBinaryPath(),+ [+ "-v",+ "error",+ "-select_streams",+ "v:0",+ "-count_frames",+ "-show_entries",+ "stream=duration,nb_frames,nb_read_frames,avg_frame_rate,r_frame_rate",+ "-of",+ "json",+ filePath,+ ],+ { timeout: 30000, maxBuffer: 2 * 1024 * 1024 },+ );+ const stdout = typeof result === "string" ? result : result.stdout;+ return parseFfprobeVideoStreamDuration(stdout);+ } catch {+ return null;+ }+}++export async function probeVideoStreamDurationSeconds(filePath: string): Promise<number> {+ const probe = await probeVideoStreamDuration(filePath);+ return probe?.durationSeconds && probe.durationSeconds > 0+ ? probe.durationSeconds+ : probeMediaDurationSeconds(filePath);+}++export function getRecordingDiagnosticsPath(videoPath: string) {+ return `${videoPath.replace(/\.[^.]+$/u, "")}.recording-diagnostics.json`;+}++function truncateDiagnosticsText(value: string | undefined, maxLength = 12000) {+ if (!value || value.length <= maxLength) {+ return value;+ }++ return `${value.slice(-maxLength)}\n[recordly: truncated to last ${maxLength} chars]`;+}++async function describeMediaFile(filePath: string | null | undefined) {+ if (!filePath) {+ return null;+ }++ try {+ const stat = await fs.stat(filePath);+ if (!stat.isFile()) {+ return {+ path: filePath,+ exists: false,+ };+ }++ return {+ path: filePath,+ exists: true,+ sizeBytes: stat.size,+ containerDurationSeconds: await probeMediaDurationSeconds(filePath),+ };+ } catch {+ return {+ path: filePath,+ exists: false,+ };+ }+}++async function describeVideoFile(filePath: string | null | undefined) {+ const media = await describeMediaFile(filePath);+ if (!media?.exists || !filePath) {+ return media;+ }++ return {+ ...media,+ stream: await probeVideoStreamDuration(filePath),+ };+}++async function describeAudioFile(filePath: string | null | undefined) {+ const media = await describeMediaFile(filePath);+ if (!media?.exists || !filePath) {+ return media;+ }++ const startDelayMs = await getCompanionAudioStartDelayMs(filePath);+ return {+ ...media,+ startDelayMs,+ };+}++export async function writeRecordingDiagnosticsSnapshot(+ videoPath: string,+ snapshot: RecordingDiagnosticsSnapshot,+) {+ const diagnosticsPath = getRecordingDiagnosticsPath(videoPath);+ const now = new Date().toISOString();+ let existing: RecordingDiagnosticsLog | null = null;++ try {+ const raw = await fs.readFile(diagnosticsPath, "utf8");+ const parsed = parseJsonWithByteOrderMark<RecordingDiagnosticsLog | null>(raw);+ if (parsed?.version === 1 && Array.isArray(parsed.events)) {+ existing = parsed;+ }+ } catch {+ // First diagnostics event for this recording.+ }++ const event = {+ timestamp: now,+ ...snapshot,+ processOutput: truncateDiagnosticsText(snapshot.processOutput),+ media: {+ video: await describeVideoFile(videoPath),+ systemAudio: await describeAudioFile(snapshot.systemAudioPath),+ microphone: await describeAudioFile(snapshot.microphonePath),+ },+ };+ const log: RecordingDiagnosticsLog = existing ?? {+ version: 1,+ createdAt: now,+ updatedAt: now,+ videoPath,+ diagnosticsPath,+ events: [],+ };+ log.updatedAt = now;+ log.videoPath = videoPath;+ log.diagnosticsPath = diagnosticsPath;+ log.events.push(event);+ log.latest = event;++ await fs.writeFile(diagnosticsPath, JSON.stringify(log, null, 2), "utf8");+ return diagnosticsPath;+}+export async function getUsableCompanionAudioCandidates(videoPath: string,): Promise<CompanionAudioCandidate[]> {@@ -123,8 +361,7 @@ async function readCompanionAudioTimingMetadata(): Promise<CompanionAudioTimingMetadata | null> {try {const raw = await fs.readFile(`${companionPath}.json`, "utf8");- const parsed =- parseJsonWithByteOrderMark<CompanionAudioTimingMetadata | null>(raw);+ const parsed = parseJsonWithByteOrderMark<CompanionAudioTimingMetadata | null>(raw);if (!parsed || typeof parsed !== "object") {return null;}diff --git a/electron/ipc/recording/windows.ts b/electron/ipc/recording/windows.tsindex 72d641e5..6fc6c035 100644--- a/electron/ipc/recording/windows.ts+++ b/electron/ipc/recording/windows.ts@@ -32,6 +32,7 @@ import {getCompanionAudioStartDelayMs,getRecordingAudioMuxTimeoutMs,probeMediaDurationSeconds,+ probeVideoStreamDurationSeconds,validateRecordedVideo,} from "./diagnostics";import { emitRecordingInterrupted } from "./events";@@ -39,6 +40,33 @@ import { emitRecordingInterrupted } from "./events";const execFileAsync = promisify(execFile);const MIN_NATIVE_WINDOWS_VIDEO_PAD_MS = 500;+export type NativeWindowsVideoPaddingResult = {+ padded: boolean;+ durationSeconds: number;+ containerDurationSeconds: number;+ targetDurationSeconds: number;+ padDurationSeconds: number;+};++export type NativeWindowsAudioMuxResult = {+ muxed: boolean;+ videoDurationSeconds: number;+ muxTimeoutMs: number;+ audioInputs: string[];+ audio: Record<+ string,+ {+ path: string;+ sizeBytes: number;+ durationSeconds: number;+ startDelayMs: number | null;+ adjustment: AudioSyncAdjustment;+ }+ >;+ outputPath?: string;+ keptAudioSidecars: boolean;+};+export async function isNativeWindowsCaptureAvailable(): Promise<boolean> {if (process.platform !== "win32") return false;@@ -165,20 +193,39 @@ export function attachWindowsCaptureLifecycle(proc: ChildProcessWithoutNullStreaexport async function extendNativeWindowsVideoToDuration(videoPath: string,targetDurationMs: number | null | undefined,-) {+): Promise<NativeWindowsVideoPaddingResult> {if (!Number.isFinite(targetDurationMs) || (targetDurationMs ?? 0) <= 0) {- return { padded: false, durationSeconds: 0 };+ return {+ padded: false,+ durationSeconds: 0,+ containerDurationSeconds: await probeMediaDurationSeconds(videoPath),+ targetDurationSeconds: 0,+ padDurationSeconds: 0,+ };}- const currentDurationSeconds = await probeMediaDurationSeconds(videoPath);+ const containerDurationSeconds = await probeMediaDurationSeconds(videoPath);+ const currentDurationSeconds = await probeVideoStreamDurationSeconds(videoPath);if (currentDurationSeconds <= 0) {- return { padded: false, durationSeconds: currentDurationSeconds };+ return {+ padded: false,+ durationSeconds: currentDurationSeconds,+ containerDurationSeconds,+ targetDurationSeconds: (targetDurationMs ?? 0) / 1000,+ padDurationSeconds: 0,+ };}const targetDurationSeconds = (targetDurationMs ?? 0) / 1000;const padDurationSeconds = targetDurationSeconds - currentDurationSeconds;if (padDurationSeconds * 1000 < MIN_NATIVE_WINDOWS_VIDEO_PAD_MS) {- return { padded: false, durationSeconds: currentDurationSeconds };+ return {+ padded: false,+ durationSeconds: currentDurationSeconds,+ containerDurationSeconds,+ targetDurationSeconds,+ padDurationSeconds: Math.max(0, padDurationSeconds),+ };}const ffmpegPath = getFfmpegBinaryPath();@@ -213,7 +260,13 @@ export async function extendNativeWindowsVideoToDuration();await validateRecordedVideo(paddedOutputPath);await moveFileWithOverwrite(paddedOutputPath, videoPath);- return { padded: true, durationSeconds: targetDurationSeconds };+ return {+ padded: true,+ durationSeconds: targetDurationSeconds,+ containerDurationSeconds,+ targetDurationSeconds,+ padDurationSeconds,+ };} catch (error) {await fs.rm(paddedOutputPath, { force: true }).catch(() => undefined);throw error;@@ -224,12 +277,13 @@ export async function muxNativeWindowsVideoWithAudio(videoPath: string,systemAudioPath: string | null,micAudioPath: string | null,-) {+): Promise<NativeWindowsAudioMuxResult> {const ffmpegPath = getFfmpegBinaryPath();const keepAudioSidecars = shouldKeepRecordingAudioSidecars();const inputs: string[] = ["-i", videoPath];const audioInputs: string[] = [];const audioFilePaths: string[] = [];+ const audio: NativeWindowsAudioMuxResult["audio"] = {};for (const [label, audioPath] of [["system", systemAudioPath],@@ -248,16 +302,36 @@ export async function muxNativeWindowsVideoWithAudio(inputs.push("-i", audioPath);audioInputs.push(label);audioFilePaths.push(audioPath);+ audio[label] = {+ path: audioPath,+ sizeBytes: stat.size,+ durationSeconds: 0,+ startDelayMs: null,+ adjustment: {+ mode: "none",+ delayMs: 0,+ tempoRatio: 1,+ durationDeltaMs: 0,+ },+ };} catch {console.warn(`[mux-win] Skipping ${label} audio: file not accessible (${audioPath})`);}}- if (audioInputs.length === 0) return;-- const videoDuration = await probeMediaDurationSeconds(videoPath);+ const videoDuration = await probeVideoStreamDurationSeconds(videoPath);const muxTimeoutMs = getRecordingAudioMuxTimeoutMs(videoDuration);const audioAdjustments: Map<string, AudioSyncAdjustment> = new Map();+ if (audioInputs.length === 0) {+ return {+ muxed: false,+ videoDurationSeconds: videoDuration,+ muxTimeoutMs,+ audioInputs,+ audio,+ keptAudioSidecars: keepAudioSidecars,+ };+ }if (videoDuration > 0) {for (let i = 0; i < audioFilePaths.length; i++) {@@ -268,6 +342,12 @@ export async function muxNativeWindowsVideoWithAudio(recordedStartDelayMs,);audioAdjustments.set(audioInputs[i], adjustment);+ audio[audioInputs[i]] = {+ ...audio[audioInputs[i]],+ durationSeconds: audioDuration,+ startDelayMs: recordedStartDelayMs,+ adjustment,+ };if (Number.isFinite(recordedStartDelayMs) && adjustment.mode === "delay") {console.log(`[mux-win] ${audioInputs[i]} audio recorded a start delay of ${adjustment.delayMs}ms`,@@ -398,7 +478,15 @@ export async function muxNativeWindowsVideoWithAudio(console.log(`[mux-win] Keeping native audio sidecars because ${RECORDING_AUDIO_SIDECAR_DEBUG_ENV} is enabled`,);- return;+ return {+ muxed: true,+ videoDurationSeconds: videoDuration,+ muxTimeoutMs,+ audioInputs,+ audio,+ outputPath: videoPath,+ keptAudioSidecars: true,+ };}for (const audioPath of [systemAudioPath, micAudioPath]) {@@ -409,4 +497,14 @@ export async function muxNativeWindowsVideoWithAudio(]);}}++ return {+ muxed: true,+ videoDurationSeconds: videoDuration,+ muxTimeoutMs,+ audioInputs,+ audio,+ outputPath: videoPath,+ keptAudioSidecars: false,+ };}diff --git a/electron/ipc/register/recording.ts b/electron/ipc/register/recording.tsindex c7d95ca4..60db86ab 100644--- a/electron/ipc/register/recording.ts+++ b/electron/ipc/register/recording.ts@@ -38,12 +38,17 @@ import {getWindowsCaptureExePath,} from "../paths/binaries";import { rememberApprovedLocalReadPath } from "../project/manager";-import { shouldKeepRecordingAudioSidecars } from "../recording/audioFilters";+import {+ getBrowserMicSidecarFilters,+ shouldKeepRecordingAudioSidecars,+} from "../recording/audioFilters";import {getCompanionAudioFallbackInfo,getFileSizeIfPresent,+ type RecordingDiagnosticsSnapshot,recordNativeCaptureDiagnostics,validateRecordedVideo,+ writeRecordingDiagnosticsSnapshot,} from "../recording/diagnostics";import {buildFfmpegCaptureArgs,@@ -142,6 +147,102 @@ import { resolveWindowsCaptureDisplay } from "../windowsCaptureSelection";const execFileAsync = promisify(execFile);+async function writeWindowsRecordingDiagnostics(+ videoPath: string | null | undefined,+ snapshot: Omit<RecordingDiagnosticsSnapshot, "backend">,+) {+ if (!videoPath) {+ return null;+ }++ try {+ return await writeRecordingDiagnosticsSnapshot(videoPath, {+ backend: "windows-wgc",+ ...snapshot,+ });+ } catch (error) {+ console.warn("Failed to write Windows recording diagnostics:", error);+ return null;+ }+}++function isRecord(value: unknown): value is Record<string, unknown> {+ return Boolean(value && typeof value === "object" && !Array.isArray(value));+}++function pickPrimitiveRecord(value: unknown) {+ if (!isRecord(value)) {+ return null;+ }++ const entries = Object.entries(value).filter(+ (entry): entry is [string, boolean | number | string] => {+ const primitive = entry[1];+ return (+ typeof primitive === "boolean" ||+ typeof primitive === "number" ||+ typeof primitive === "string"+ );+ },+ );++ return entries.length > 0 ? Object.fromEntries(entries) : null;+}++function pickMicrophoneChunkEvents(value: unknown) {+ if (!Array.isArray(value)) {+ return null;+ }++ const events = value+ .map((event) => {+ if (!isRecord(event)) {+ return null;+ }++ const { index, size, elapsedMs, deltaMs } = event;+ if (+ typeof index !== "number" ||+ typeof size !== "number" ||+ typeof elapsedMs !== "number"+ ) {+ return null;+ }++ return {+ index: Math.round(index),+ size: Math.round(size),+ elapsedMs: Math.round(elapsedMs),+ deltaMs: typeof deltaMs === "number" ? Math.round(deltaMs) : null,+ };+ })+ .filter((event): event is NonNullable<typeof event> => event !== null);++ return events.length > 0 ? events : null;+}++function pickAudioInputDevices(value: unknown) {+ if (!Array.isArray(value)) {+ return null;+ }++ const devices = value+ .map((device) => {+ if (!isRecord(device) || typeof device.deviceId !== "string") {+ return null;+ }++ return {+ deviceId: device.deviceId,+ ...(typeof device.groupId === "string" ? { groupId: device.groupId } : {}),+ label: typeof device.label === "string" ? device.label : "",+ };+ })+ .filter((device): device is NonNullable<typeof device> => device !== null);++ return devices.length > 0 ? devices : null;+}+async function getSystemCursorAssets() {if (process.platform !== "darwin") {setCachedSystemCursorAssets({});@@ -656,6 +757,8 @@ export function registerRecordingHandlers(const proc = windowsCaptureProcess;const preferredVideoPath = windowsCaptureTargetPath;const preferredOrphanedMicAudioPath = windowsOrphanedMicAudioPath;+ const diagnosticsSystemAudioPath = windowsSystemAudioPath;+ const diagnosticsMicAudioPath = windowsMicAudioPath;setWindowsCaptureStopRequested(true);proc.stdin.write("stop\n");const tempVideoPath = await waitForWindowsCaptureStop(proc);@@ -679,16 +782,29 @@ export function registerRecordingHandlers(backend: "windows-wgc",phase: "stop",outputPath: finalVideoPath,- systemAudioPath: windowsSystemAudioPath,- microphonePath: windowsMicAudioPath,+ systemAudioPath: diagnosticsSystemAudioPath,+ microphonePath: diagnosticsMicAudioPath,processOutput: windowsCaptureOutputBuffer.trim() || undefined,fileSizeBytes: validation.fileSizeBytes,});+ await writeWindowsRecordingDiagnostics(finalVideoPath, {+ phase: "stop",+ outputPath: finalVideoPath,+ systemAudioPath: diagnosticsSystemAudioPath,+ microphonePath: diagnosticsMicAudioPath,+ processOutput: windowsCaptureOutputBuffer.trim() || undefined,+ details: {+ fileSizeBytes: validation.fileSizeBytes,+ durationSeconds: validation.durationSeconds,+ },+ });return { success: true, path: finalVideoPath };} catch (error) {console.error("Failed to stop native Windows capture:", error);const fallbackPath = windowsCaptureTargetPath;const fallbackOrphanedMicAudioPath = windowsOrphanedMicAudioPath;+ const diagnosticsSystemAudioPath = windowsSystemAudioPath;+ const diagnosticsMicAudioPath = windowsMicAudioPath;setWindowsNativeCaptureActive(false);setNativeScreenRecordingActive(false);setWindowsCaptureProcess(null);@@ -710,12 +826,25 @@ export function registerRecordingHandlers(backend: "windows-wgc",phase: "stop",outputPath: fallbackPath,- systemAudioPath: windowsSystemAudioPath,- microphonePath: windowsMicAudioPath,+ systemAudioPath: diagnosticsSystemAudioPath,+ microphonePath: diagnosticsMicAudioPath,processOutput: windowsCaptureOutputBuffer.trim() || undefined,fileSizeBytes: validation.fileSizeBytes,error: String(error),});+ await writeWindowsRecordingDiagnostics(fallbackPath, {+ phase: "stop",+ outputPath: fallbackPath,+ systemAudioPath: diagnosticsSystemAudioPath,+ microphonePath: diagnosticsMicAudioPath,+ processOutput: windowsCaptureOutputBuffer.trim() || undefined,+ error: String(error),+ details: {+ fileSizeBytes: validation.fileSizeBytes,+ durationSeconds: validation.durationSeconds,+ recoveredAfterStopFailure: true,+ },+ });return { success: true, path: fallbackPath };} catch {// File is absent or failed validation.@@ -726,12 +855,23 @@ export function registerRecordingHandlers(backend: "windows-wgc",phase: "stop",outputPath: fallbackPath,- systemAudioPath: windowsSystemAudioPath,- microphonePath: windowsMicAudioPath,+ systemAudioPath: diagnosticsSystemAudioPath,+ microphonePath: diagnosticsMicAudioPath,processOutput: windowsCaptureOutputBuffer.trim() || undefined,fileSizeBytes: await getFileSizeIfPresent(fallbackPath),error: String(error),});+ await writeWindowsRecordingDiagnostics(fallbackPath, {+ phase: "stop",+ outputPath: fallbackPath,+ systemAudioPath: diagnosticsSystemAudioPath,+ microphonePath: diagnosticsMicAudioPath,+ processOutput: windowsCaptureOutputBuffer.trim() || undefined,+ error: String(error),+ details: {+ fileSizeBytes: await getFileSizeIfPresent(fallbackPath),+ },+ });return {success: false,@@ -1046,6 +1186,8 @@ export function registerRecordingHandlers(ipcMain.handle("mux-native-windows-recording", async (_event, expectedDurationMs?: number) => {const videoPath = windowsPendingVideoPath;const orphanedMicAudioPath = windowsOrphanedMicAudioPath;+ const diagnosticsSystemAudioPath = windowsSystemAudioPath;+ const diagnosticsMicAudioPath = windowsMicAudioPath;setWindowsPendingVideoPath(null);setWindowsOrphanedMicAudioPath(null);@@ -1054,11 +1196,31 @@ export function registerRecordingHandlers(}try {+ await writeWindowsRecordingDiagnostics(videoPath, {+ phase: "mux-start",+ expectedDurationMs,+ outputPath: videoPath,+ systemAudioPath: diagnosticsSystemAudioPath,+ microphonePath: diagnosticsMicAudioPath,+ details: {+ hasSystemAudio: Boolean(diagnosticsSystemAudioPath),+ hasMicrophone: Boolean(diagnosticsMicAudioPath),+ hasOrphanedMicrophone: Boolean(orphanedMicAudioPath),+ },+ });try {const padding = await extendNativeWindowsVideoToDuration(videoPath,expectedDurationMs,);+ await writeWindowsRecordingDiagnostics(videoPath, {+ phase: "pad",+ expectedDurationMs,+ outputPath: videoPath,+ systemAudioPath: diagnosticsSystemAudioPath,+ microphonePath: diagnosticsMicAudioPath,+ details: { ...padding },+ });if (padding.padded) {console.log(`[mux-win] Extended native Windows video to ${padding.durationSeconds.toFixed(3)}s using the final frame`,@@ -1069,13 +1231,22 @@ export function registerRecordingHandlers("[mux-win] Failed to extend native Windows video duration:",paddingError,);+ await writeWindowsRecordingDiagnostics(videoPath, {+ phase: "pad",+ expectedDurationMs,+ outputPath: videoPath,+ systemAudioPath: diagnosticsSystemAudioPath,+ microphonePath: diagnosticsMicAudioPath,+ error: String(paddingError),+ });}- if (windowsSystemAudioPath || windowsMicAudioPath) {- await muxNativeWindowsVideoWithAudio(+ let muxDetails: unknown = null;+ if (diagnosticsSystemAudioPath || diagnosticsMicAudioPath) {+ muxDetails = await muxNativeWindowsVideoWithAudio(videoPath,- windowsSystemAudioPath,- windowsMicAudioPath,+ diagnosticsSystemAudioPath,+ diagnosticsMicAudioPath,);setWindowsSystemAudioPath(null);setWindowsMicAudioPath(null);@@ -1087,6 +1258,17 @@ export function registerRecordingHandlers(outputPath: videoPath,fileSizeBytes: await getFileSizeIfPresent(videoPath),});+ await writeWindowsRecordingDiagnostics(videoPath, {+ phase: "mux-complete",+ expectedDurationMs,+ outputPath: videoPath,+ systemAudioPath: diagnosticsSystemAudioPath,+ microphonePath: diagnosticsMicAudioPath,+ details: {+ fileSizeBytes: await getFileSizeIfPresent(videoPath),+ mux: muxDetails,+ },+ });await cleanupWindowsOrphanedMicAudioPath(orphanedMicAudioPath);return await finalizeStoredVideo(videoPath);} catch (error) {@@ -1095,11 +1277,22 @@ export function registerRecordingHandlers(backend: "windows-wgc",phase: "mux",outputPath: videoPath,- systemAudioPath: windowsSystemAudioPath,- microphonePath: windowsMicAudioPath,+ systemAudioPath: diagnosticsSystemAudioPath,+ microphonePath: diagnosticsMicAudioPath,fileSizeBytes: await getFileSizeIfPresent(videoPath),error: String(error),});+ await writeWindowsRecordingDiagnostics(videoPath, {+ phase: "mux-error",+ expectedDurationMs,+ outputPath: videoPath,+ systemAudioPath: diagnosticsSystemAudioPath,+ microphonePath: diagnosticsMicAudioPath,+ error: String(error),+ details: {+ fileSizeBytes: await getFileSizeIfPresent(videoPath),+ },+ });setWindowsSystemAudioPath(null);setWindowsMicAudioPath(null);await cleanupWindowsOrphanedMicAudioPath(orphanedMicAudioPath);@@ -1213,19 +1406,104 @@ export function registerRecordingHandlers(_,audioData: ArrayBuffer,videoPath: string,- options?: { startDelayMs?: number },+ options?: {+ startDelayMs?: number;+ browserMicrophoneProfile?: string;+ requestedBrowserMicrophoneProfile?: string | null;+ requestedConstraints?: unknown;+ mediaTrackSettings?: Record<string, boolean | number | string>;+ audioInputDevices?: unknown;+ mediaRecorder?: unknown;+ chunkEvents?: unknown;+ },) => {+ const baseName = videoPath.replace(/\.[^.]+$/, "");+ const sidecarPath = `${baseName}.mic.wav`;+ const sourceWebmPath = `${baseName}.mic.source.webm`;+ const tempWebmPath = `${sourceWebmPath}.tmp`;+try {- const baseName = videoPath.replace(/\.[^.]+$/, "");- const sidecarPath = `${baseName}.mic.webm`;- await fs.writeFile(sidecarPath, Buffer.from(audioData));+ await fs.writeFile(tempWebmPath, Buffer.from(audioData));+ await execFileAsync(+ getFfmpegBinaryPath(),+ [+ "-y",+ "-hide_banner",+ "-nostdin",+ "-nostats",+ "-i",+ tempWebmPath,+ "-vn",+ "-ac",+ "1",+ "-ar",+ "48000",+ "-af",+ [+ ...getBrowserMicSidecarFilters(options?.browserMicrophoneProfile),+ "aresample=async=1:first_pts=0",+ ].join(","),+ "-c:a",+ "pcm_s16le",+ sidecarPath,+ ],+ { timeout: 120000, maxBuffer: 10 * 1024 * 1024 },+ );+ if (shouldKeepRecordingAudioSidecars()) {+ await fs.rename(tempWebmPath, sourceWebmPath).catch(async () => {+ await fs.copyFile(tempWebmPath, sourceWebmPath);+ await fs.rm(tempWebmPath, { force: true });+ });+ } else {+ await fs.rm(tempWebmPath, { force: true });+ }const startDelayMs = options?.startDelayMs;- if (Number.isFinite(startDelayMs) && (startDelayMs ?? 0) >= 0) {+ const mediaTrackSettings = pickPrimitiveRecord(options?.mediaTrackSettings);+ const audioInputDevices = pickAudioInputDevices(options?.audioInputDevices);+ const mediaRecorder = isRecord(options?.mediaRecorder)+ ? {+ ...(typeof options.mediaRecorder.mimeType === "string"+ ? { mimeType: options.mediaRecorder.mimeType }+ : {}),+ ...(typeof options.mediaRecorder.audioBitsPerSecond === "number"+ ? {+ audioBitsPerSecond: Math.round(+ options.mediaRecorder.audioBitsPerSecond,+ ),+ }+ : {}),+ ...(typeof options.mediaRecorder.timesliceMs === "number"+ ? { timesliceMs: Math.round(options.mediaRecorder.timesliceMs) }+ : {}),+ }+ : null;+ const chunkEvents = pickMicrophoneChunkEvents(options?.chunkEvents);+ const metadata = {+ ...(Number.isFinite(startDelayMs) && (startDelayMs ?? 0) >= 0+ ? { startDelayMs: Math.round(startDelayMs ?? 0) }+ : {}),+ ...(typeof options?.browserMicrophoneProfile === "string"+ ? { browserMicrophoneProfile: options.browserMicrophoneProfile }+ : {}),+ ...(typeof options?.requestedBrowserMicrophoneProfile === "string"+ ? {+ requestedBrowserMicrophoneProfile:+ options.requestedBrowserMicrophoneProfile,+ }+ : {}),+ ...(isRecord(options?.requestedConstraints)+ ? { requestedConstraints: options.requestedConstraints }+ : {}),+ ...(mediaTrackSettings ? { mediaTrackSettings } : {}),+ ...(audioInputDevices ? { audioInputDevices } : {}),+ ...(mediaRecorder && Object.keys(mediaRecorder).length > 0+ ? { mediaRecorder }+ : {}),+ ...(chunkEvents ? { chunkEvents } : {}),+ };+ if (Object.keys(metadata).length > 0) {try {- await fs.writeFile(- `${sidecarPath}.json`,- JSON.stringify({ startDelayMs: Math.round(startDelayMs ?? 0) }),- );+ await fs.writeFile(`${sidecarPath}.json`, JSON.stringify(metadata));} catch (metadataError) {console.warn("Failed to store microphone sidecar timing metadata:",@@ -1233,8 +1511,28 @@ export function registerRecordingHandlers();}}+ await writeRecordingDiagnosticsSnapshot(videoPath, {+ backend: "browser-store",+ phase: "mic-sidecar",+ outputPath: videoPath,+ microphonePath: sidecarPath,+ details: {+ sourceBytes: audioData.byteLength,+ sourceWebmPath: shouldKeepRecordingAudioSidecars() ? sourceWebmPath : null,+ metadata,+ },+ }).catch((diagnosticsError) => {+ console.warn(+ "Failed to write microphone sidecar diagnostics:",+ diagnosticsError,+ );+ });return { success: true, path: sidecarPath };} catch (error) {+ await Promise.all([+ fs.rm(tempWebmPath, { force: true }).catch(() => undefined),+ fs.rm(sidecarPath, { force: true }).catch(() => undefined),+ ]);console.error("Failed to store microphone sidecar:", error);return { success: false, error: String(error) };}diff --git a/electron/ipc/register/settings.ts b/electron/ipc/register/settings.tsindex 3f05a590..4622bb2d 100644--- a/electron/ipc/register/settings.ts+++ b/electron/ipc/register/settings.ts@@ -19,6 +19,27 @@ import {} from "../state";import { parseJsonWithByteOrderMark } from "../utils";+const BROWSER_MICROPHONE_PROFILE_ENV = "RECORDLY_BROWSER_MIC_PROFILE";+const DEFAULT_BROWSER_MICROPHONE_PROFILE = "no-agc";+const BROWSER_MICROPHONE_PROFILES = new Set([+ "processed",+ "no-agc",+ "no-echo",+ "no-noise-suppression",+ "raw",+]);++function getBrowserMicrophoneProfileFromEnv() {+ const requested = process.env[BROWSER_MICROPHONE_PROFILE_ENV]?.trim() || null;+ const normalized = requested?.toLowerCase() ?? DEFAULT_BROWSER_MICROPHONE_PROFILE;+ return {+ browserMicrophoneProfile: BROWSER_MICROPHONE_PROFILES.has(normalized)+ ? normalized+ : DEFAULT_BROWSER_MICROPHONE_PROFILE,+ requestedBrowserMicrophoneProfile: requested,+ };+}+export function registerSettingsHandlers() {ipcMain.handle('app:getVersion', () => {return app.getVersion()@@ -70,13 +91,17 @@ export function registerSettingsHandlers() {success: true,microphoneEnabled: parsed.microphoneEnabled === true,microphoneDeviceId: typeof parsed.microphoneDeviceId === 'string' ? parsed.microphoneDeviceId : undefined,- systemAudioEnabled: parsed.systemAudioEnabled !== false,+ systemAudioEnabled: parsed.systemAudioEnabled === true,}} catch {- return { success: true, microphoneEnabled: false, microphoneDeviceId: undefined, systemAudioEnabled: true }+ return { success: true, microphoneEnabled: false, microphoneDeviceId: undefined, systemAudioEnabled: false }}})+ ipcMain.handle('get-recording-audio-lab-config', () => {+ return getBrowserMicrophoneProfileFromEnv()+ })+ipcMain.handle('set-recording-preferences', async (_, prefs: { microphoneEnabled?: boolean; microphoneDeviceId?: string; systemAudioEnabled?: boolean }) => {try {let existing: Record<string, unknown> = {}diff --git a/electron/main.ts b/electron/main.tsindex 0bbb0be6..fdeed2c0 100644--- a/electron/main.ts+++ b/electron/main.ts@@ -55,6 +55,18 @@ import {const __dirname = path.dirname(fileURLToPath(import.meta.url));const IS_SMOKE_EXPORT = process.env.RECORDLY_SMOKE_EXPORT === "1";+function ignoreBrokenConsolePipe(stream: NodeJS.WritableStream | undefined) {+ stream?.on("error", (error: NodeJS.ErrnoException) => {+ if (error.code === "EPIPE") {+ return;+ }+ throw error;+ });+}++ignoreBrokenConsolePipe(process.stdout);+ignoreBrokenConsolePipe(process.stderr);+app.commandLine.appendSwitch("ignore-gpu-blocklist");app.commandLine.appendSwitch("enable-unsafe-webgpu");app.commandLine.appendSwitch("enable-gpu-rasterization");diff --git a/electron/native/bin/win32-x64/helpers-manifest.json b/electron/native/bin/win32-x64/helpers-manifest.jsonindex 53baaf7a..9a5427f7 100644--- a/electron/native/bin/win32-x64/helpers-manifest.json+++ b/electron/native/bin/win32-x64/helpers-manifest.json@@ -8,28 +8,28 @@"binarySha256": "88226bd499c820081a27264b40f37875d0949d9f921920738e05b7eaeb1a9e7d","sourceDir": "electron/native/wgc-capture","sourceFingerprint": "7190e148ede1fb1c573cc1866405d6345b0c35378a7e32499580bffacf1cc6d2",- "updatedAt": "2026-05-06T16:09:49.253Z"+ "updatedAt": "2026-05-07T15:21:44.354Z"},"cursor-monitor": {"binaryName": "cursor-monitor.exe","binarySha256": "6ae6d91103b6e891a851e8ea5791e1c1f9aaab700134c18bc4c46cfffd7fdd12","sourceDir": "electron/native/cursor-monitor","sourceFingerprint": "6ad1b8b50bb336f2a48937b06f5ec56d90b6ab4a3e56a4bca278cf67a5d3e52e",- "updatedAt": "2026-05-05T18:42:26.007Z"+ "updatedAt": "2026-05-07T15:22:18.173Z"},"recordly-gpu-export": {"binaryName": "recordly-gpu-export.exe","binarySha256": "f147901f01dd5b410f67a5c0feae5064ea7556a878b333aa493e799498abb5e5","sourceDir": "electron/native/gpu-export-probe","sourceFingerprint": "056a4c41113c471379d0ec6095249c46a79b05fac5fc0e52ce0bfdf6de4d91e1",- "updatedAt": "2026-05-06T13:51:01.756Z"+ "updatedAt": "2026-05-07T15:21:50.702Z"},"recordly-nvidia-cuda-compositor": {"binaryName": "recordly-nvidia-cuda-compositor.exe",- "binarySha256": "ec594808577011407fe40ea4e610a6b6fd2cbc7c5dde4627f48351a8a5a980c3",+ "binarySha256": "c02a3326b1f840df788a206d288164d428156177ce64aa1331d87e7913826b77","sourceDir": "electron/native/nvidia-cuda-compositor",- "sourceFingerprint": "6dd2a015326ac984c0a88581c809d628592f174e02a6813d24356c22e7384f1a",- "updatedAt": "2026-05-06T13:51:30.019Z"+ "sourceFingerprint": "5388602559cbfb98ab18dd3ad96ce55897c0a548febaeb9304d26a0201b296b0",+ "updatedAt": "2026-05-07T15:22:12.014Z"}}}diff --git a/electron/native/bin/win32-x64/recordly-nvidia-cuda-compositor.exe b/electron/native/bin/win32-x64/recordly-nvidia-cuda-compositor.exeindex b3183623..453025ee 100644Binary files a/electron/native/bin/win32-x64/recordly-nvidia-cuda-compositor.exe and b/electron/native/bin/win32-x64/recordly-nvidia-cuda-compositor.exe differdiff --git a/electron/native/nvidia-cuda-compositor/run-mp4-pipeline.mjs b/electron/native/nvidia-cuda-compositor/run-mp4-pipeline.mjsindex a9a5ae73..d6b643a0 100644--- a/electron/native/nvidia-cuda-compositor/run-mp4-pipeline.mjs+++ b/electron/native/nvidia-cuda-compositor/run-mp4-pipeline.mjs@@ -931,6 +931,10 @@ const outputPath = resolve();const fps = Math.round(getNumberArg("--fps", 30));const bitrateMbps = Math.round(getNumberArg("--bitrate-mbps", 18));+const encodingMode = getArg("--encoding-mode", "balanced");+if (!["fast", "balanced", "quality"].includes(encodingMode)) {+ throw new Error(`Unsupported --encoding-mode: ${encodingMode}`);+}const workDir = resolve(getArg("--work-dir", join(scriptDir, "mp4-work")));const reuseIntermediates = hasArg("--reuse-intermediates");const reuseDemux = hasArg("--reuse-demux") || reuseIntermediates;@@ -1260,6 +1264,8 @@ const encodeArgs = [String(targetFrames),"--bitrate-mbps",String(bitrateMbps),+ "--encoding-mode",+ encodingMode,"--callback-encode","--chunk-mb",String(chunkMb),@@ -1456,6 +1462,7 @@ console.log(outputPath,fps,bitrateMbps,+ encodingMode,streamSync,prewarmMs,maxOutputFrames,diff --git a/electron/native/nvidia-cuda-compositor/src/main.cu b/electron/native/nvidia-cuda-compositor/src/main.cuindex 9dccdaad..c7791d34 100644--- a/electron/native/nvidia-cuda-compositor/src/main.cu+++ b/electron/native/nvidia-cuda-compositor/src/main.cu@@ -44,6 +44,7 @@ struct Options {int inputFrames = 0;int targetFrames = 0;int bitrateMbps = 18;+ std::string encodingMode = "balanced";bool postSelect = false;bool callbackEncode = false;bool streamSync = false;@@ -174,6 +175,14 @@ Options parseOptions(int argc, char** argv) {options.targetFrames = parsePositiveInt(requireValue("--target-frames"), "--target-frames");} else if (arg == "--bitrate-mbps") {options.bitrateMbps = parsePositiveInt(requireValue("--bitrate-mbps"), "--bitrate-mbps");+ } else if (arg == "--encoding-mode") {+ options.encodingMode = requireValue("--encoding-mode");+ if (+ options.encodingMode != "fast" &&+ options.encodingMode != "balanced" &&+ options.encodingMode != "quality") {+ fail("Unsupported --encoding-mode: " + options.encodingMode);+ }} else if (arg == "--post-select") {options.postSelect = true;} else if (arg == "--callback-encode") {@@ -254,7 +263,7 @@ Options parseOptions(int argc, char** argv) {} else if (arg == "--help") {std::cout << "Usage: recordly-nvidia-cuda-compositor --input input.annexb.h264 ""[--output out.h264] [--source-pts source-pts.csv] [--fps 30] "- "[--max-frames N] [--bitrate-mbps N] "+ "[--max-frames N] [--bitrate-mbps N] [--encoding-mode fast|balanced|quality] ""[--post-select] [--callback-encode] [--stream-sync] [--prewarm-ms N] [--chunk-mb N] ""[--content-x N --content-y N --content-width N --content-height N --radius N] ""[--background-nv12 background.nv12] [--shadow-offset-y N --shadow-intensity-pct N] "@@ -1914,6 +1923,23 @@ void prewarmCuda(int durationMs) {checkCuda(cudaFree(state), "cudaFree prewarm");}+GUID getNvencPresetGuid(const std::string& encodingMode) {+ return encodingMode == "fast" ? NV_ENC_PRESET_HP_GUID : NV_ENC_PRESET_HQ_GUID;+}++uint32_t getNvencMaxBitrate(uint32_t bitrate, const std::string& encodingMode) {+ const uint64_t multiplier = encodingMode == "fast" ? 3 : 2;+ const uint64_t divisor = encodingMode == "fast" ? 2 : 1;+ return static_cast<uint32_t>(+ std::min<uint64_t>(0xffffffffu, (static_cast<uint64_t>(bitrate) * multiplier) / divisor));+}++uint32_t getNvencBufferSize(uint32_t bitrate, const std::string& encodingMode) {+ const uint64_t multiplier = encodingMode == "fast" ? 1 : 2;+ return static_cast<uint32_t>(+ std::min<uint64_t>(0xffffffffu, static_cast<uint64_t>(bitrate) * multiplier));+}+class NvencSink {public:NvencSink(@@ -1947,7 +1973,10 @@ public:NV_ENC_INITIALIZE_PARAMS initializeParams = {NV_ENC_INITIALIZE_PARAMS_VER};NV_ENC_CONFIG encodeConfig = {NV_ENC_CONFIG_VER};initializeParams.encodeConfig = &encodeConfig;- encoder_.CreateDefaultEncoderParams(&initializeParams, NV_ENC_CODEC_H264_GUID, NV_ENC_PRESET_HP_GUID);+ encoder_.CreateDefaultEncoderParams(+ &initializeParams,+ NV_ENC_CODEC_H264_GUID,+ getNvencPresetGuid(layoutOptions_.encodingMode));initializeParams.frameRateNum = static_cast<uint32_t>(fps);initializeParams.frameRateDen = 1;@@ -1957,10 +1986,13 @@ public:encodeConfig.frameIntervalP = 1;encodeConfig.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR;encodeConfig.rcParams.averageBitRate = bitrate;- encodeConfig.rcParams.maxBitRate = static_cast<uint32_t>(- std::min<uint64_t>(0xffffffffu, static_cast<uint64_t>(bitrate) * 3 / 2));- encodeConfig.rcParams.vbvBufferSize = bitrate;+ encodeConfig.rcParams.maxBitRate = getNvencMaxBitrate(bitrate, layoutOptions_.encodingMode);+ encodeConfig.rcParams.vbvBufferSize = getNvencBufferSize(bitrate, layoutOptions_.encodingMode);encodeConfig.rcParams.vbvInitialDelay = bitrate;+ if (layoutOptions_.encodingMode != "fast") {+ encodeConfig.rcParams.enableAQ = 1;+ encodeConfig.rcParams.aqStrength = layoutOptions_.encodingMode == "quality" ? 10 : 8;+ }encodeConfig.encodeCodecConfig.h264Config.idrPeriod = encodeConfig.gopLength;encoder_.CreateEncoder(&initializeParams);@@ -3118,6 +3150,7 @@ int main(int argc, char** argv) {<< "\"width\":" << decoder->GetWidth() << ","<< "\"height\":" << decoder->GetHeight() << ","<< "\"fps\":" << options.fps << ","+ << "\"encodingMode\":\"" << options.encodingMode << "\","<< "\"staticLayout\":" << (hasStaticLayout(options) ? "true" : "false") << ","<< "\"contentX\":" << options.contentX << ","<< "\"contentY\":" << options.contentY << ","diff --git a/electron/preload.ts b/electron/preload.tsindex b47ec5a1..ff037462 100644--- a/electron/preload.ts+++ b/electron/preload.ts@@ -258,6 +258,7 @@ contextBridge.exposeInMainWorld("electronAPI", {audioOptions?: {audioMode?: "none" | "copy-source" | "trim-source" | "edited-track";audioSourcePath?: string | null;+ audioSourceCodec?: string | null;audioSourceSampleRate?: number;outputDurationSec?: number;trimSegments?: Array<{ startMs: number; endMs: number }>;@@ -320,6 +321,7 @@ contextBridge.exposeInMainWorld("electronAPI", {options?: {audioMode?: "none" | "copy-source" | "trim-source" | "edited-track";audioSourcePath?: string | null;+ audioSourceCodec?: string | null;audioSourceSampleRate?: number;outputDurationSec?: number;trimSegments?: Array<{ startMs: number; endMs: number }>;@@ -367,6 +369,7 @@ contextBridge.exposeInMainWorld("electronAPI", {options?: {audioMode?: "none" | "copy-source" | "trim-source" | "edited-track";audioSourcePath?: string | null;+ audioSourceCodec?: string | null;audioSourceSampleRate?: number;outputDurationSec?: number;trimSegments?: Array<{ startMs: number; endMs: number }>;@@ -388,6 +391,7 @@ contextBridge.exposeInMainWorld("electronAPI", {options?: {audioMode?: "none" | "copy-source" | "trim-source" | "edited-track";audioSourcePath?: string | null;+ audioSourceCodec?: string | null;audioSourceSampleRate?: number;outputDurationSec?: number;trimSegments?: Array<{ startMs: number; endMs: number }>;@@ -491,7 +495,29 @@ contextBridge.exposeInMainWorld("electronAPI", {storeMicrophoneSidecar: (audioData: ArrayBuffer,videoPath: string,- options?: { startDelayMs?: number },+ options?: {+ startDelayMs?: number;+ browserMicrophoneProfile?: string;+ requestedBrowserMicrophoneProfile?: string | null;+ requestedConstraints?: unknown;+ mediaTrackSettings?: Record<string, boolean | number | string>;+ audioInputDevices?: Array<{+ deviceId: string;+ groupId?: string;+ label: string;+ }>;+ mediaRecorder?: {+ mimeType?: string;+ audioBitsPerSecond?: number;+ timesliceMs?: number;+ };+ chunkEvents?: Array<{+ index: number;+ size: number;+ elapsedMs: number;+ deltaMs: number | null;+ }>;+ },) => {return ipcRenderer.invoke("store-microphone-sidecar", audioData, videoPath, options);},@@ -840,6 +866,7 @@ contextBridge.exposeInMainWorld("electronAPI", {hideOsCursor: () => ipcRenderer.invoke("hide-cursor"),getAppVersion: () => ipcRenderer.invoke("app:getVersion"),getRecordingPreferences: () => ipcRenderer.invoke("get-recording-preferences"),+ getRecordingAudioLabConfig: () => ipcRenderer.invoke("get-recording-audio-lab-config"),setRecordingPreferences: (prefs: {microphoneEnabled?: boolean;microphoneDeviceId?: string;diff --git a/src/components/video-editor/VideoEditor.tsx b/src/components/video-editor/VideoEditor.tsxindex e8e8ce98..20e9da77 100644--- a/src/components/video-editor/VideoEditor.tsx+++ b/src/components/video-editor/VideoEditor.tsx@@ -5171,6 +5171,16 @@ export default function VideoEditor() {100,): null;+ const exportFinalizingPercent = isExportFinalizing+ ? Math.round(exportFinalizingProgress ?? 100)+ : null;+ const isExportMuxingAndSaving =+ isExportFinalizing &&+ exportFormat === "mp4" &&+ exportPipelineModel === "modern" &&+ !isRenderingAudio;+ const isExportFinalSaveIndeterminate =+ isExportMuxingAndSaving && (exportFinalizingPercent ?? 0) >= 98;const isLightningExportInProgress =exportFormat === "mp4" &&exportPipelineModel === "modern" &&@@ -5234,15 +5244,20 @@ export default function VideoEditor() {}): isExportFinalizing? exportFormat === "mp4" && exportPipelineModel === "modern"- ? t(+ ? isExportFinalSaveIndeterminate+ ? t(+ "editor.exportStatus.muxingAndSaving",+ "Muxing audio and saving file...",+ )+ : t("editor.exportStatus.muxingAndSavingPercent","Muxing and saving {{percent}}%",{- percent: Math.round(exportFinalizingProgress ?? 100),+ percent: exportFinalizingPercent ?? 100,},): t("editor.exportStatus.finalizingPercent", "Finalizing {{percent}}%", {- percent: Math.round(exportFinalizingProgress ?? 100),+ percent: exportFinalizingPercent ?? 100,}): t("editor.exportStatus.completePercent", "{{percent}}% complete", {percent: Math.round(exportProgress.percentage),@@ -5584,7 +5599,9 @@ export default function VideoEditor() {</Button></div><div className="h-2 overflow-hidden rounded-full border border-foreground/5 bg-foreground/5">- {isExportPreparing || isExportSaving ? (+ {isExportPreparing ||+ isExportSaving ||+ isExportFinalSaveIndeterminate ? (<div className="indeterminate-progress h-full rounded-full bg-transparent" />) : (<divdiff --git a/src/hooks/useScreenRecorder.test.ts b/src/hooks/useScreenRecorder.test.tsindex ac133712..6a613459 100644--- a/src/hooks/useScreenRecorder.test.ts+++ b/src/hooks/useScreenRecorder.test.ts@@ -1,5 +1,10 @@import { beforeEach, describe, expect, it, vi } from "vitest";+import {+ createProcessedMicrophoneConstraints,+ normalizeBrowserMicrophoneProfile,+} from "./useScreenRecorder";+type RecordingState = "inactive" | "recording" | "paused";function createMockMediaRecorder(initialState: RecordingState = "inactive") {@@ -23,6 +28,85 @@ function createMockMediaRecorder(initialState: RecordingState = "inactive") {};}+describe("createProcessedMicrophoneConstraints", () => {+ it("requests browser voice processing without AGC for the default microphone", () => {+ expect(createProcessedMicrophoneConstraints()).toEqual({+ audio: {+ echoCancellation: true,+ noiseSuppression: true,+ autoGainControl: false,+ channelCount: { ideal: 1 },+ sampleRate: { ideal: 48000 },+ },+ video: false,+ });+ });++ it("keeps no-AGC voice processing when a specific microphone is selected", () => {+ expect(createProcessedMicrophoneConstraints("device-123")).toMatchObject({+ audio: {+ deviceId: { exact: "device-123" },+ echoCancellation: true,+ noiseSuppression: true,+ autoGainControl: false,+ channelCount: { ideal: 1 },+ sampleRate: { ideal: 48000 },+ },+ video: false,+ });+ });++ it("can request the legacy browser processed profile for lab comparisons", () => {+ expect(createProcessedMicrophoneConstraints(undefined, "processed")).toMatchObject({+ audio: {+ echoCancellation: true,+ noiseSuppression: true,+ autoGainControl: true,+ },+ video: false,+ });+ });++ it("can disable AGC for lab comparisons", () => {+ expect(createProcessedMicrophoneConstraints(undefined, "no-agc")).toMatchObject({+ audio: {+ echoCancellation: true,+ noiseSuppression: true,+ autoGainControl: false,+ },+ video: false,+ });+ });++ it("can disable echo cancellation for lab comparisons", () => {+ expect(createProcessedMicrophoneConstraints(undefined, "no-echo")).toMatchObject({+ audio: {+ echoCancellation: false,+ noiseSuppression: true,+ autoGainControl: true,+ },+ video: false,+ });+ });++ it("can request a raw browser microphone stream for lab comparisons", () => {+ expect(createProcessedMicrophoneConstraints(undefined, "raw")).toMatchObject({+ audio: {+ echoCancellation: false,+ noiseSuppression: false,+ autoGainControl: false,+ },+ video: false,+ });+ });++ it("normalizes invalid lab microphone profiles to production no-AGC processing", () => {+ expect(normalizeBrowserMicrophoneProfile("RAW")).toBe("raw");+ expect(normalizeBrowserMicrophoneProfile("unknown")).toBe("no-agc");+ expect(normalizeBrowserMicrophoneProfile(null)).toBe("no-agc");+ });+});+function stopRecording(recorder: ReturnType<typeof createMockMediaRecorder>,isNativeRecording: boolean,diff --git a/src/hooks/useScreenRecorder.ts b/src/hooks/useScreenRecorder.tsindex bb0f3046..d16683aa 100644--- a/src/hooks/useScreenRecorder.ts+++ b/src/hooks/useScreenRecorder.ts@@ -32,7 +32,7 @@ const RECORDING_FILE_PREFIX = "recording-";const VIDEO_FILE_EXTENSION = ".webm";const AUDIO_BITRATE_VOICE = 128_000;const AUDIO_BITRATE_SYSTEM = 192_000;-const MIC_GAIN_BOOST = 1.4;+const MIC_GAIN_BOOST = 1;const WEBCAM_BITRATE = 8_000_000;const WEBCAM_WIDTH = 1280;const WEBCAM_HEIGHT = 720;@@ -41,6 +41,65 @@ const WEBCAM_SUFFIX = "-webcam";const SOURCE_AUDIO_MUX_TOAST_ID = "recording-audio-mux-warning";const MICROPHONE_FALLBACK_ERROR_TOAST_ID = "recording-microphone-fallback-error";const MICROPHONE_SIDECAR_ERROR_TOAST_ID = "recording-microphone-sidecar-error";+export type BrowserMicrophoneProfile =+ | "processed"+ | "no-agc"+ | "no-echo"+ | "no-noise-suppression"+ | "raw";+const DEFAULT_BROWSER_MICROPHONE_PROFILE: BrowserMicrophoneProfile = "no-agc";+const BROWSER_MICROPHONE_PROFILES = new Set<BrowserMicrophoneProfile>([+ "processed",+ "no-agc",+ "no-echo",+ "no-noise-suppression",+ "raw",+]);+type MicrophoneTrackSettingsSnapshot = Partial<+ Pick<+ MediaTrackSettings,+ | "autoGainControl"+ | "channelCount"+ | "deviceId"+ | "echoCancellation"+ | "groupId"+ | "noiseSuppression"+ | "sampleRate"+ | "sampleSize"+ >+> & {+ trackId?: string;+ trackLabel?: string;+ trackEnabled?: boolean;+ trackMuted?: boolean;+ trackReadyState?: MediaStreamTrackState;+};+type MicrophoneAudioInputDeviceSnapshot = {+ deviceId: string;+ groupId?: string;+ label: string;+};+type MicrophoneFallbackChunkEvent = {+ index: number;+ size: number;+ elapsedMs: number;+ deltaMs: number | null;+};+type MicrophoneFallbackRecorderMetadata = {+ mimeType: string;+ audioBitsPerSecond: number;+ timesliceMs: number;+};+type MicrophoneSidecarOptions = {+ startDelayMs?: number;+ browserMicrophoneProfile?: BrowserMicrophoneProfile;+ requestedBrowserMicrophoneProfile?: string | null;+ requestedConstraints?: MediaStreamConstraints;+ mediaTrackSettings?: MicrophoneTrackSettingsSnapshot;+ audioInputDevices?: MicrophoneAudioInputDeviceSnapshot[];+ mediaRecorder?: MicrophoneFallbackRecorderMetadata;+ chunkEvents?: MicrophoneFallbackChunkEvent[];+};const LINUX_PORTAL_SOURCE: ProcessedDesktopSource = {id: "screen:linux-portal",name: "Linux Portal",@@ -110,6 +169,88 @@ function getErrorMessage(error: unknown) {return "An unexpected error occurred";}+export function normalizeBrowserMicrophoneProfile(value?: string | null): BrowserMicrophoneProfile {+ const normalized = value?.trim().toLowerCase();+ return normalized && BROWSER_MICROPHONE_PROFILES.has(normalized as BrowserMicrophoneProfile)+ ? (normalized as BrowserMicrophoneProfile)+ : DEFAULT_BROWSER_MICROPHONE_PROFILE;+}++export function createProcessedMicrophoneConstraints(+ microphoneDeviceId?: string,+ profile: BrowserMicrophoneProfile = DEFAULT_BROWSER_MICROPHONE_PROFILE,+): MediaStreamConstraints {+ const normalizedProfile = normalizeBrowserMicrophoneProfile(profile);+ const audio: MediaTrackConstraints = {+ echoCancellation: normalizedProfile !== "no-echo" && normalizedProfile !== "raw",+ noiseSuppression:+ normalizedProfile !== "no-noise-suppression" && normalizedProfile !== "raw",+ autoGainControl: normalizedProfile !== "no-agc" && normalizedProfile !== "raw",+ channelCount: { ideal: 1 },+ sampleRate: { ideal: 48000 },+ };++ if (microphoneDeviceId) {+ audio.deviceId = { exact: microphoneDeviceId };+ }++ return { audio, video: false };+}++function createMicrophoneTrackSettingsSnapshot(+ stream: MediaStream,+): MicrophoneTrackSettingsSnapshot | null {+ const track = stream.getAudioTracks()[0];+ const settings = track?.getSettings?.();+ if (!track || !settings) {+ return null;+ }++ const snapshot: MicrophoneTrackSettingsSnapshot = {+ trackId: track.id,+ trackLabel: track.label,+ trackEnabled: track.enabled,+ trackMuted: track.muted,+ trackReadyState: track.readyState,+ };+ for (const key of [+ "autoGainControl",+ "channelCount",+ "deviceId",+ "echoCancellation",+ "groupId",+ "noiseSuppression",+ "sampleRate",+ "sampleSize",+ ] as const) {+ const value = settings[key];+ if (value !== undefined) {+ snapshot[key] = value as never;+ }+ }++ return Object.keys(snapshot).length > 0 ? snapshot : null;+}++async function createAudioInputDeviceSnapshot(): Promise<+ MicrophoneAudioInputDeviceSnapshot[] | null+> {+ if (typeof navigator.mediaDevices?.enumerateDevices !== "function") {+ return null;+ }++ const devices = await navigator.mediaDevices.enumerateDevices();+ const audioInputs = devices+ .filter((device) => device.kind === "audioinput")+ .map((device) => ({+ deviceId: device.deviceId,+ ...(device.groupId ? { groupId: device.groupId } : {}),+ label: device.label,+ }));++ return audioInputs.length > 0 ? audioInputs : null;+}+export function useScreenRecorder(): UseScreenRecorderReturn {const [recording, setRecording] = useState(false);const [paused, setPaused] = useState(false);@@ -152,6 +293,16 @@ export function useScreenRecorder(): UseScreenRecorderReturn {const micFallbackRecorder = useRef<MediaRecorder | null>(null);const micFallbackChunks = useRef<Blob[]>([]);const micFallbackStartDelayMs = useRef<number | null>(null);+ const micFallbackTrackSettings = useRef<MicrophoneTrackSettingsSnapshot | null>(null);+ const micFallbackRequestedConstraints = useRef<MediaStreamConstraints | null>(null);+ const micFallbackAudioInputDevices = useRef<MicrophoneAudioInputDeviceSnapshot[] | null>(null);+ const micFallbackRecorderMetadata = useRef<MicrophoneFallbackRecorderMetadata | null>(null);+ const micFallbackChunkEvents = useRef<MicrophoneFallbackChunkEvent[]>([]);+ const micFallbackRecorderStartedAt = useRef<number | null>(null);+ const browserMicrophoneProfile = useRef<BrowserMicrophoneProfile>(+ DEFAULT_BROWSER_MICROPHONE_PROFILE,+ );+ const requestedBrowserMicrophoneProfile = useRef<string | null>(null);const hideEditorOverlayCursorByDefault = useRef(false);const notifyRecordingFinalizationFailure = useCallback(async (message: string) => {@@ -342,7 +493,34 @@ export function useScreenRecorder(): UseScreenRecorderReturn {}micFallbackRecorder.current = null;micFallbackChunks.current = [];+ micFallbackTrackSettings.current = null;+ micFallbackRequestedConstraints.current = null;+ micFallbackAudioInputDevices.current = null;+ micFallbackRecorderMetadata.current = null;+ micFallbackChunkEvents.current = [];+ micFallbackRecorderStartedAt.current = null;+ }+ }, []);++ const appendMicFallbackChunk = useCallback((event: BlobEvent) => {+ if (event.data.size <= 0) {+ return;+ }++ micFallbackChunks.current.push(event.data);+ const startedAt = micFallbackRecorderStartedAt.current;+ if (startedAt === null) {+ return;}++ const elapsedMs = Math.max(0, Math.round(performance.now() - startedAt));+ const previous = micFallbackChunkEvents.current[micFallbackChunkEvents.current.length - 1];+ micFallbackChunkEvents.current.push({+ index: micFallbackChunkEvents.current.length,+ size: event.data.size,+ elapsedMs,+ deltaMs: previous ? Math.max(0, elapsedMs - previous.elapsedMs) : null,+ });}, []);const resolveBrowserCaptureSource = useCallback(async (source: ProcessedDesktopSource) => {@@ -436,11 +614,7 @@ export function useScreenRecorder(): UseScreenRecorderReturn {resolve(null);return;}- recorder.ondataavailable = (event) => {- if (event.data.size > 0) {- micFallbackChunks.current.push(event.data);- }- };+ recorder.ondataavailable = appendMicFallbackChunk;recorder.onstop = () => {const blob =micFallbackChunks.current.length > 0@@ -449,31 +623,67 @@ export function useScreenRecorder(): UseScreenRecorderReturn {micFallbackChunks.current = [];recorder.stream.getTracks().forEach((track) => track.stop());micFallbackRecorder.current = null;+ micFallbackRecorderStartedAt.current = null;resolve(blob);};recorder.stop();});- }, []);+ }, [appendMicFallbackChunk]);const storeMicrophoneSidecar = useCallback(async (micFallbackBlobPromise: Promise<Blob | null> | null | undefined,finalPath: string,startDelayMs?: number | null,+ mediaTrackSettings?: MicrophoneTrackSettingsSnapshot | null,) => {const micFallbackBlob = await micFallbackBlobPromise;if (!micFallbackBlob) {+ micFallbackStartDelayMs.current = null;+ micFallbackTrackSettings.current = null;+ micFallbackRequestedConstraints.current = null;+ micFallbackAudioInputDevices.current = null;+ micFallbackRecorderMetadata.current = null;+ micFallbackChunkEvents.current = [];return;}try {const arrayBuffer = await micFallbackBlob.arrayBuffer();+ const effectiveStartDelayMs = startDelayMs ?? micFallbackStartDelayMs.current;+ const effectiveTrackSettings =+ mediaTrackSettings ?? micFallbackTrackSettings.current;+ const sidecarOptions: MicrophoneSidecarOptions = {+ ...(Number.isFinite(effectiveStartDelayMs) && (effectiveStartDelayMs ?? 0) >= 0+ ? { startDelayMs: effectiveStartDelayMs ?? 0 }+ : {}),+ browserMicrophoneProfile: browserMicrophoneProfile.current,+ ...(requestedBrowserMicrophoneProfile.current+ ? {+ requestedBrowserMicrophoneProfile:+ requestedBrowserMicrophoneProfile.current,+ }+ : {}),+ ...(micFallbackRequestedConstraints.current+ ? { requestedConstraints: micFallbackRequestedConstraints.current }+ : {}),+ ...(effectiveTrackSettings+ ? { mediaTrackSettings: effectiveTrackSettings }+ : {}),+ ...(micFallbackAudioInputDevices.current+ ? { audioInputDevices: micFallbackAudioInputDevices.current }+ : {}),+ ...(micFallbackRecorderMetadata.current+ ? { mediaRecorder: micFallbackRecorderMetadata.current }+ : {}),+ ...(micFallbackChunkEvents.current.length > 0+ ? { chunkEvents: [...micFallbackChunkEvents.current] }+ : {}),+ };const result = await window.electronAPI.storeMicrophoneSidecar(arrayBuffer,finalPath,- Number.isFinite(startDelayMs) && (startDelayMs ?? 0) >= 0- ? { startDelayMs: startDelayMs ?? 0 }- : undefined,+ sidecarOptions,);if (!result.success) {const errorMessage =@@ -490,6 +700,13 @@ export function useScreenRecorder(): UseScreenRecorderReturn {`${getErrorMessage(error)}. Recording was saved without the fallback microphone track.`,{ id: MICROPHONE_SIDECAR_ERROR_TOAST_ID, duration: 10000 },);+ } finally {+ micFallbackStartDelayMs.current = null;+ micFallbackTrackSettings.current = null;+ micFallbackRequestedConstraints.current = null;+ micFallbackAudioInputDevices.current = null;+ micFallbackRecorderMetadata.current = null;+ micFallbackChunkEvents.current = [];}},[],@@ -682,6 +899,7 @@ export function useScreenRecorder(): UseScreenRecorderReturn {void (async () => {const fallbackStartDelayMs = micFallbackStartDelayMs.current;+ const fallbackTrackSettings = micFallbackTrackSettings.current;const stoppedAtMs = Date.now();markRecordingResumed(stoppedAtMs);const expectedDurationMs = getRecordingDurationMs(stoppedAtMs);@@ -748,6 +966,7 @@ export function useScreenRecorder(): UseScreenRecorderReturn {micFallbackBlobPromise,finalPath,fallbackStartDelayMs,+ fallbackTrackSettings,);await finalizeRecordingSession(finalPath, webcamPath);@@ -782,6 +1001,22 @@ export function useScreenRecorder(): UseScreenRecorderReturn {})();}, []);+ useEffect(() => {+ if (typeof window.electronAPI?.getRecordingAudioLabConfig !== "function") {+ return;+ }++ void (async () => {+ const result = await window.electronAPI.getRecordingAudioLabConfig();+ browserMicrophoneProfile.current = normalizeBrowserMicrophoneProfile(+ result.browserMicrophoneProfile,+ );+ requestedBrowserMicrophoneProfile.current =+ result.requestedBrowserMicrophoneProfile ?? null;+ console.info("Browser microphone profile:", browserMicrophoneProfile.current);+ })();+ }, []);+useEffect(() => {if (countdownDelayLoaded.current) return;countdownDelayLoaded.current = true;@@ -1042,30 +1277,38 @@ export function useScreenRecorder(): UseScreenRecorderReturn {void logNativeCaptureDiagnostics("start-browser-microphone-fallback");console.info("Using browser microphone processing for this recording.");try {- const micStream = await navigator.mediaDevices.getUserMedia({- audio: microphoneDeviceId- ? {- deviceId: { exact: microphoneDeviceId },- echoCancellation: true,- noiseSuppression: true,- autoGainControl: true,- }- : {- echoCancellation: true,- noiseSuppression: true,- autoGainControl: true,- },- video: false,- });+ const microphoneConstraints = createProcessedMicrophoneConstraints(+ microphoneDeviceId,+ browserMicrophoneProfile.current,+ );+ micFallbackRequestedConstraints.current = microphoneConstraints;+ const micStream =+ await navigator.mediaDevices.getUserMedia(microphoneConstraints);+ micFallbackTrackSettings.current =+ createMicrophoneTrackSettingsSnapshot(micStream);+ micFallbackAudioInputDevices.current =+ await createAudioInputDeviceSnapshot().catch(() => null);+ console.info(+ "Browser microphone track settings:",+ micFallbackTrackSettings.current,+ );+ console.info(+ "Browser microphone audio input devices:",+ micFallbackAudioInputDevices.current,+ );micFallbackChunks.current = [];const recorder = new MediaRecorder(micStream, {mimeType: "audio/webm;codecs=opus",+ audioBitsPerSecond: AUDIO_BITRATE_VOICE,});- recorder.ondataavailable = (event) => {- if (event.data.size > 0) {- micFallbackChunks.current.push(event.data);- }+ micFallbackRecorderMetadata.current = {+ mimeType: recorder.mimeType,+ audioBitsPerSecond: AUDIO_BITRATE_VOICE,+ timesliceMs: RECORDER_TIMESLICE_MS,};+ micFallbackChunkEvents.current = [];+ micFallbackRecorderStartedAt.current = performance.now();+ recorder.ondataavailable = appendMicFallbackChunk;micFallbackStartDelayMs.current = Math.max(0,Date.now() - mainStartedAt,@@ -1074,6 +1317,12 @@ export function useScreenRecorder(): UseScreenRecorderReturn {micFallbackRecorder.current = recorder;} catch (micError) {micFallbackStartDelayMs.current = null;+ micFallbackTrackSettings.current = null;+ micFallbackRequestedConstraints.current = null;+ micFallbackAudioInputDevices.current = null;+ micFallbackRecorderMetadata.current = null;+ micFallbackChunkEvents.current = [];+ micFallbackRecorderStartedAt.current = null;console.warn("Browser microphone fallback failed:", micError);const permissionDenied =micError instanceof DOMException &&@@ -1197,21 +1446,12 @@ export function useScreenRecorder(): UseScreenRecorderReturn {if (microphoneEnabled) {try {- microphoneStream.current = await navigator.mediaDevices.getUserMedia({- audio: microphoneDeviceId- ? {- deviceId: { exact: microphoneDeviceId },- echoCancellation: true,- noiseSuppression: true,- autoGainControl: true,- }- : {- echoCancellation: true,- noiseSuppression: true,- autoGainControl: true,- },- video: false,- });+ microphoneStream.current = await navigator.mediaDevices.getUserMedia(+ createProcessedMicrophoneConstraints(+ microphoneDeviceId,+ browserMicrophoneProfile.current,+ ),+ );} catch (audioError) {console.warn("Failed to get microphone access:", audioError);alert(diff --git a/src/lib/exporter/exportBitrate.test.ts b/src/lib/exporter/exportBitrate.test.tsindex df6cabb4..5b6c5f91 100644--- a/src/lib/exporter/exportBitrate.test.ts+++ b/src/lib/exporter/exportBitrate.test.ts@@ -15,7 +15,17 @@ describe("export bitrate policy", () => {).toBe(27_000_000);});- it("caps modern native static-layout source exports to avoid bitrate inflation", () => {+ it("keeps modern native static-layout source exports high enough for screen text", () => {+ expect(+ getMp4ExportBitrate({+ width: 1920,+ height: 1080,+ frameRate: 30,+ quality: "source",+ encodingMode: "balanced",+ useModernNativeStaticLayout: true,+ }),+ ).toBe(22_000_000);expect(getMp4ExportBitrate({width: 1920,@@ -25,7 +35,7 @@ describe("export bitrate policy", () => {encodingMode: "quality",useModernNativeStaticLayout: true,}),- ).toBe(14_000_000);+ ).toBe(27_000_000);});it("does not raise fast exports when the requested bitrate is already lower than the cap", () => {@@ -51,6 +61,6 @@ describe("export bitrate policy", () => {encodingMode: "quality",useModernNativeStaticLayout: true,}),- ).toBe(28_000_000);+ ).toBe(72_000_000);});});diff --git a/src/lib/exporter/exportBitrate.ts b/src/lib/exporter/exportBitrate.tsindex ccef876c..7d3fa240 100644--- a/src/lib/exporter/exportBitrate.ts+++ b/src/lib/exporter/exportBitrate.ts@@ -48,11 +48,35 @@ function getModernNativeStaticLayoutBitrateCap(quality: ExportQuality,): number {const referenceCap =- quality === "source" ? 14_000_000 : quality === "high" ? 12_000_000 : 8_000_000;+ quality === "source"+ ? 36_000_000+ : quality === "high"+ ? 28_000_000+ : quality === "good"+ ? 20_000_000+ : 14_000_000;const pixelRateScale = Math.max((width * height * frameRate) / REFERENCE_PIXEL_RATE, 0.1);return Math.round(referenceCap * Math.sqrt(pixelRateScale));}+function getModernNativeStaticLayoutBitrateFloor(+ width: number,+ height: number,+ frameRate: ExportMp4FrameRate,+ quality: ExportQuality,+): number {+ const referenceFloor =+ quality === "source"+ ? 22_000_000+ : quality === "high"+ ? 16_000_000+ : quality === "good"+ ? 12_000_000+ : 8_000_000;+ const pixelRateScale = Math.max((width * height * frameRate) / REFERENCE_PIXEL_RATE, 0.1);+ return Math.round(referenceFloor * Math.sqrt(pixelRateScale));+}+export function getMp4ExportBitrate(options: {width: number;height: number;@@ -65,9 +89,21 @@ export function getMp4ExportBitrate(options: {getBaseMp4ExportBitrate(options.width, options.height, options.quality) *getEncodingModeBitrateMultiplier(options.encodingMode),);+ const nativeStaticLayoutBitrate =+ options.useModernNativeStaticLayout && options.encodingMode !== "fast"+ ? Math.max(+ requestedBitrate,+ getModernNativeStaticLayoutBitrateFloor(+ options.width,+ options.height,+ options.frameRate,+ options.quality,+ ),+ )+ : requestedBitrate;const cappedBitrate = options.useModernNativeStaticLayout? Math.min(- requestedBitrate,+ nativeStaticLayoutBitrate,getModernNativeStaticLayoutBitrateCap(options.width,options.height,diff --git a/src/lib/exporter/modernVideoExporter.nativeStaticLayout.test.ts b/src/lib/exporter/modernVideoExporter.nativeStaticLayout.test.tsindex e4e893cf..3f295bc0 100644--- a/src/lib/exporter/modernVideoExporter.nativeStaticLayout.test.ts+++ b/src/lib/exporter/modernVideoExporter.nativeStaticLayout.test.ts@@ -66,6 +66,49 @@ afterEach(() => {});describe("ModernVideoExporter native static-layout eligibility", () => {+ it("allows native static-layout eligibility for VP9/WebM sources so main can proxy them", () => {+ const exporter = createExporter();++ expect(+ exporter.getNativeStaticLayoutSkipReason(+ { audioMode: "none" },+ {+ ...videoInfo,+ codec: "vp9 (Profile 0)",+ audioCodec: "opus",+ },+ 60,+ ),+ ).toBeNull();+ });++ it("carries embedded audio codec into native mux options", () => {+ const exporter = createExporter();++ expect(+ exporter.buildNativeAudioPlan({+ ...videoInfo,+ codec: "vp9 (Profile 0)",+ audioCodec: "opus",+ }),+ ).toMatchObject({+ audioMode: "copy-source",+ audioSourceCodec: "opus",+ });+ });++ it("allows native static-layout for H.264 source metadata", () => {+ const exporter = createExporter();++ expect(+ exporter.getNativeStaticLayoutSkipReason(+ { audioMode: "none" },+ { ...videoInfo, codec: "avc1.640034" },+ 60,+ ),+ ).toBeNull();+ });+it("uses FFmpeg filtergraph audio for speed edits with a single external source track", () => {const speedRegions: SpeedRegion[] = [{ id: "speed-1", startMs: 1_000, endMs: 4_000, speed: 1.5 },diff --git a/src/lib/exporter/modernVideoExporter.ts b/src/lib/exporter/modernVideoExporter.tsindex 38a58964..9019bcad 100644--- a/src/lib/exporter/modernVideoExporter.ts+++ b/src/lib/exporter/modernVideoExporter.ts@@ -148,6 +148,7 @@ type NativeAudioPlan =| {audioMode: "copy-source" | "trim-source";audioSourcePath: string;+ audioSourceCodec?: string;trimSegments?: Array<{ startMs: number; endMs: number }>;}| {@@ -158,6 +159,7 @@ type NativeAudioPlan =audioMode: "edited-track";strategy: "filtergraph-fast-path";audioSourcePath: string;+ audioSourceCodec?: string;audioSourceSampleRate: number;editedTrackSegments: Array<{ startMs: number; endMs: number; speed: number }>;};@@ -1058,6 +1060,7 @@ export class ModernVideoExporter {const primaryAudioSourceSampleRate = usesEmbeddedPrimaryAudio? videoInfo.audioSampleRate: FILTERGRAPH_FALLBACK_AUDIO_SAMPLE_RATE;+ const primaryAudioSourceCodec = usesEmbeddedPrimaryAudio ? videoInfo.audioCodec : undefined;if (!videoInfo.hasAudio &&@@ -1114,6 +1117,7 @@ export class ModernVideoExporter {audioMode: "edited-track",strategy,audioSourcePath,+ audioSourceCodec: primaryAudioSourceCodec,audioSourceSampleRate,editedTrackSegments,};@@ -1146,6 +1150,7 @@ export class ModernVideoExporter {return {audioMode: "trim-source",audioSourcePath: primaryAudioSourcePath,+ audioSourceCodec: primaryAudioSourceCodec,trimSegments,};}@@ -1153,6 +1158,7 @@ export class ModernVideoExporter {return {audioMode: "copy-source",audioSourcePath: primaryAudioSourcePath,+ audioSourceCodec: primaryAudioSourceCodec,};}@@ -1649,6 +1655,7 @@ export class ModernVideoExporter {return {audioMode: audioPlan.audioMode,audioSourcePath: audioPlan.audioSourcePath,+ audioSourceCodec: audioPlan.audioSourceCodec,trimSegments: audioPlan.trimSegments,};case "edited-track": {@@ -1656,6 +1663,7 @@ export class ModernVideoExporter {return {audioMode: audioPlan.audioMode,audioSourcePath: audioPlan.audioSourcePath,+ audioSourceCodec: audioPlan.audioSourceCodec,audioSourceSampleRate: audioPlan.audioSourceSampleRate,editedTrackStrategy: audioPlan.strategy,editedTrackSegments: audioPlan.editedTrackSegments,