Create polished demo videos without editing skills. Mac/Windows/Linux
fix screenrecorder webcam
Alan Trebugeais6c1a5612737f
diff --git a/DIAGNOSTICS_PLAN.md b/DIAGNOSTICS_PLAN.mddeleted file mode 100644index 318af0e5..00000000--- a/DIAGNOSTICS_PLAN.md+++ /dev/null@@ -1,39 +0,0 @@-# Plan de Diagnostic de Performance : "Stop Recording"--L'objectif est d'identifier précisément les goulots d'étranglement qui causent un délai de 10-15 secondes après l'arrêt d'un enregistrement natif sur Windows.--## 1. Instrumentation Frontend (`src/hooks/useScreenRecorder.ts`)--Nous allons mesurer le temps total côté UI et le temps d'attente pour chaque appel IPC majeur.--- **Total Stop Sequence** : Du clic sur "Stop" à l'ouverture de l'éditeur.-- **IPC: stopNativeScreenRecording** : Temps d'arrêt du processus de capture natif.-- **IPC: muxNativeWindowsRecording** : Temps passé dans FFmpeg pour le padding et le muxing audio.-- **Store Sidecar** : Temps d'écriture de l'audio du microphone enregistré par le navigateur.--## 2. Instrumentation Main Process IPC (`electron/ipc/register/recording.ts`)--Nous allons mesurer le temps passé dans les handlers IPC pour différencier le temps de traitement de l'overhead de communication.--- **Handler: stop-native-screen-recording**-- **Handler: mux-native-windows-recording**--## 3. Instrumentation Logique Interne (`electron/ipc/recording/windows.ts`)--C'est ici que se trouvent les opérations FFmpeg suspectées.--- **extendNativeWindowsVideoToDuration** : Temps de re-encodage pour ajouter du padding (Suspect #1).-- **muxNativeWindowsVideoWithAudio** : Temps de muxing audio (Suspect #2).-- **Probing** : Temps passé dans `ffprobe`.--## Méthodologie d'analyse--Une fois les logs ajoutés :-1. Lancer l'app en mode dev.-2. Faire un enregistrement court (10s).-3. Arrêter l'enregistrement.-4. Récupérer les logs dans :- - La **Console du navigateur** (pour le frontend).- - Le **Terminal** (pour le processus main d'Electron).--Les logs seront préfixés par `[PERF:RENDERER]` et `[PERF:MAIN]`.diff --git a/electron/electron-env.d.ts b/electron/electron-env.d.tsindex cdd90881..a2f81889 100644--- a/electron/electron-env.d.ts+++ b/electron/electron-env.d.ts@@ -71,6 +71,7 @@ type RendererMarketplaceReviewStatus =import("./extensions/extensionTypes").MarketplaceReviewStatus;type RendererMarketplaceSearchResult =import("./extensions/extensionTypes").MarketplaceSearchResult;+type RendererRecordingSessionData = import("./ipc/types").RecordingSessionData;interface RendererFfmpegAudioMuxMetrics {tempVideoWriteMs?: number;@@ -561,6 +562,9 @@ interface Window {onRecordingStateChanged: (callback: (state: { recording: boolean; sourceName: string }) => void,) => () => void;+ onRecordingSessionChanged: (+ callback: (session: RendererRecordingSessionData | null) => void,+ ) => () => void;onRecordingInterrupted: (callback: (state: { reason: string; message: string }) => void,) => () => void;diff --git a/electron/ipc/recording/mac.ts b/electron/ipc/recording/mac.tsindex 0017188e..09dd5aa7 100644--- a/electron/ipc/recording/mac.ts+++ b/electron/ipc/recording/mac.ts@@ -224,7 +224,11 @@ export async function finalizeStoredVideo(videoPath: string) {snapshotCursorTelemetryForPersistence();setCurrentVideoPath(videoPath);setCurrentProjectPath(null);- await persistPendingCursorTelemetry(videoPath);+ try {+ await persistPendingCursorTelemetry(videoPath);+ } catch (error) {+ console.warn("[mac-stop] Failed to persist cursor telemetry:", error);+ }if (isAutoRecordingPath(videoPath)) {await pruneAutoRecordings([videoPath]);}diff --git a/electron/ipc/recording/windows.ts b/electron/ipc/recording/windows.tsindex 70c73cbf..f3e43db5 100644--- a/electron/ipc/recording/windows.ts+++ b/electron/ipc/recording/windows.ts@@ -188,7 +188,9 @@ export async function muxNativeWindowsVideoWithAudio(try {const stat = await fs.stat(systemAudioPath);if (stat.size > 0) {- await moveFileWithOverwrite(systemAudioPath, finalSystemPath);+ if (systemAudioPath !== finalSystemPath) {+ await moveFileWithOverwrite(systemAudioPath, finalSystemPath);+ }audioInputs.push("system");audio.system = {path: finalSystemPath,@@ -208,7 +210,9 @@ export async function muxNativeWindowsVideoWithAudio(try {const stat = await fs.stat(micAudioPath);if (stat.size > 0) {- await moveFileWithOverwrite(micAudioPath, finalMicPath);+ if (micAudioPath !== finalMicPath) {+ await moveFileWithOverwrite(micAudioPath, finalMicPath);+ }audioInputs.push("mic");audio.mic = {path: finalMicPath,diff --git a/electron/ipc/register/project.ts b/electron/ipc/register/project.tsindex 54cdc8aa..af6150ff 100644--- a/electron/ipc/register/project.ts+++ b/electron/ipc/register/project.ts@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";import { constants as fsConstants } from "node:fs";import fs from "node:fs/promises";import path from "node:path";-import { dialog, ipcMain, shell } from "electron";+import { BrowserWindow, dialog, ipcMain, shell } from "electron";import { RECORDINGS_DIR } from "../../appPaths";import { buildMediaUrl, getMediaServerBaseUrl } from "../../mediaServer";import {@@ -562,6 +562,13 @@ export function registerProjectHandlers() {if (!options?.preserveProjectPath) {setCurrentProjectPath(null)}++ for (const window of BrowserWindow.getAllWindows()) {+ if (!window.isDestroyed()) {+ window.webContents.send('recording-session-changed', nextSession);+ }+ }+return { success: true, webcamPath: nextSession.webcamPath ?? null }})@@ -582,6 +589,13 @@ export function registerProjectHandlers() {setCurrentProjectPath(null)}await persistRecordingSessionManifest(currentRecordingSession!)++ for (const window of BrowserWindow.getAllWindows()) {+ if (!window.isDestroyed()) {+ window.webContents.send('recording-session-changed', currentRecordingSession);+ }+ }+return { success: true }})diff --git a/electron/ipc/register/recording.ts b/electron/ipc/register/recording.tsindex 3e8b4c93..feb6aefb 100644--- a/electron/ipc/register/recording.ts+++ b/electron/ipc/register/recording.ts@@ -878,7 +878,11 @@ export function registerRecordingHandlers(// Persist cursor telemetry before returning so the editor can find it immediatelysnapshotCursorTelemetryForPersistence();- await persistPendingCursorTelemetry(finalVideoPath);+ try {+ await persistPendingCursorTelemetry(finalVideoPath);+ } catch (error) {+ console.warn("Failed to persist cursor telemetry during native stop:", error);+ }return { success: true, path: finalVideoPath };} catch (error) {diff --git a/electron/preload.ts b/electron/preload.tsindex cfb8015f..c823de71 100644--- a/electron/preload.ts+++ b/electron/preload.ts@@ -1,4 +1,5 @@import { contextBridge, ipcRenderer } from "electron";+import type { RecordingSessionData } from "./ipc/types";type NativeVideoExportWriteResult = { success: boolean; error?: string };type NativeVideoAudioMuxMetrics = {@@ -681,6 +682,12 @@ contextBridge.exposeInMainWorld("electronAPI", {) => {return ipcRenderer.invoke("set-current-recording-session", session, options);},+ onRecordingSessionChanged: (callback: (session: RecordingSessionData | null) => void) => {+ const listener = (_event: Electron.IpcRendererEvent, payload: RecordingSessionData | null) =>+ callback(payload);+ ipcRenderer.on("recording-session-changed", listener);+ return () => ipcRenderer.removeListener("recording-session-changed", listener);+ },getCurrentRecordingSession: () => {return ipcRenderer.invoke("get-current-recording-session");},diff --git a/src/components/video-editor/VideoEditor.tsx b/src/components/video-editor/VideoEditor.tsxindex 334164cb..f3cce5e2 100644--- a/src/components/video-editor/VideoEditor.tsx+++ b/src/components/video-editor/VideoEditor.tsx@@ -2499,6 +2499,24 @@ export default function VideoEditor() {smokeExportConfig.webcamSize,]);+ useEffect(() => {+ if (!window.electronAPI.onRecordingSessionChanged) {+ return;+ }++ return window.electronAPI.onRecordingSessionChanged((session) => {+ if (!session) return;+ if (session.videoPath === videoSourcePath && session.webcamPath) {+ setWebcam((prev) => ({+ ...prev,+ enabled: true,+ sourcePath: session.webcamPath ?? null,+ timeOffsetMs: session.timeOffsetMs ?? prev.timeOffsetMs,+ }));+ }+ });+ }, [videoSourcePath]);+useEffect(() => {let cancelled = false;if (!webcam.sourcePath) {diff --git a/src/hooks/useScreenRecorder.ts b/src/hooks/useScreenRecorder.tsindex de05f21e..b524c3bb 100644--- a/src/hooks/useScreenRecorder.ts+++ b/src/hooks/useScreenRecorder.ts@@ -1029,7 +1029,6 @@ export function useScreenRecorder(): UseScreenRecorderReturn {);await window.electronAPI?.setRecordingState(false);- const webcamPath = await webcamPathPromise;if (!result.success || !result.path) {console.error(@@ -1064,29 +1063,28 @@ export function useScreenRecorder(): UseScreenRecorderReturn {const finalPath = result.path;- // 1. Immediately inform the Main process about the provisional path- const shouldHideOverlayCursor = hideEditorOverlayCursorByDefault.current;- if (webcamPath) {- await window.electronAPI.setCurrentRecordingSession({- videoPath: finalPath,- webcamPath,- timeOffsetMs: webcamTimeOffsetMs.current,- hideOverlayCursorByDefault: shouldHideOverlayCursor,- });- } else {- await window.electronAPI.setCurrentVideoPath(finalPath, {- hideOverlayCursorByDefault: shouldHideOverlayCursor,- });- }+ // 1. Finalize the session and switch to editor immediately (Optimistic UI)+ // We pass null for webcamPath initially to avoid blocking on webcam disk writes/muxing.+ await finalizeRecordingSession(finalPath, null);- // 2. Open the editor window immediately (Optimistic UI)- setFinalizing(false);- void window.electronAPI.switchToEditor();-- // 3. Perform background finalization (muxing, sidecars)+ // 2. Perform background finalization (webcam, muxing, sidecars)// We don't await this to keep the UI responsivevoid (async () => {try {+ // Await the webcam path in the background+ const webcamPath = await webcamPathPromise;++ // If we have a webcam path, update the session.+ // This will broadcast a 'recording-session-changed' event that the open editor listens to.+ if (webcamPath) {+ await window.electronAPI.setCurrentRecordingSession({+ videoPath: finalPath,+ webcamPath,+ timeOffsetMs: webcamTimeOffsetMs.current,+ hideOverlayCursorByDefault: hideEditorOverlayCursorByDefault.current,+ });+ }+// Store sidecarsawait storeMicrophoneSidecar(micFallbackBlobPromise,@@ -1743,10 +1741,25 @@ export function useScreenRecorder(): UseScreenRecorderReturn {}if (videoResult.path) {- const webcamPath = pendingWebcamPathPromise.current- ? await pendingWebcamPathPromise.current- : resolvedWebcamPath.current;- await finalizeRecordingSession(videoResult.path, webcamPath);+ const finalVideoPath = videoResult.path;+ // 1. Launch editor immediately (Optimistic UI)+ await finalizeRecordingSession(finalVideoPath, null);++ // 2. Background webcam processing+ void (async () => {+ const webcamPath = pendingWebcamPathPromise.current+ ? await pendingWebcamPathPromise.current+ : resolvedWebcamPath.current;++ if (webcamPath) {+ await window.electronAPI.setCurrentRecordingSession({+ videoPath: finalVideoPath,+ webcamPath,+ timeOffsetMs: webcamTimeOffsetMs.current,+ hideOverlayCursorByDefault: hideEditorOverlayCursorByDefault.current,+ });+ }+ })();} else {await notifyRecordingFinalizationFailure("Failed to save the recording.");}