Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix: sync webcam preview playback speed

Marcus Schiessere4263d4597cd
diff --git a/electron/electron-env.d.ts b/electron/electron-env.d.ts
index 17fd20fcc..072534803 100644
--- a/electron/electron-env.d.ts
+++ b/electron/electron-env.d.ts
@@ -29,6 +29,12 @@ interface Window {
openSourceSelector: () => Promise<void>;
selectSource: (source: ProcessedDesktopSource) => Promise<ProcessedDesktopSource | null>;
getSelectedSource: () => Promise<ProcessedDesktopSource | null>;
+ requestCameraAccess: () => Promise<{
+ success: boolean;
+ granted: boolean;
+ status: string;
+ error?: string;
+ }>;
getAssetBasePath: () => Promise<string | null>;
storeRecordedVideo: (
videoData: ArrayBuffer,
diff --git a/electron/ipc/handlers.ts b/electron/ipc/handlers.ts
index 2a6c406a2..82440c828 100644
--- a/electron/ipc/handlers.ts
+++ b/electron/ipc/handlers.ts
@@ -1,7 +1,16 @@
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
-import { app, BrowserWindow, desktopCapturer, dialog, ipcMain, screen, shell } from "electron";
+import {
+ app,
+ BrowserWindow,
+ desktopCapturer,
+ dialog,
+ ipcMain,
+ screen,
+ shell,
+ systemPreferences,
+} from "electron";
import {
normalizeProjectMedia,
normalizeRecordingSession,
@@ -185,6 +194,38 @@ export function registerIpcHandlers(
return selectedSource;
});
+ ipcMain.handle("request-camera-access", async () => {
+ if (process.platform !== "darwin") {
+ return { success: true, granted: true, status: "granted" };
+ }
+
+ try {
+ const status = systemPreferences.getMediaAccessStatus("camera");
+ if (status === "granted") {
+ return { success: true, granted: true, status };
+ }
+
+ if (status === "not-determined") {
+ const granted = await systemPreferences.askForMediaAccess("camera");
+ return {
+ success: true,
+ granted,
+ status: granted ? "granted" : systemPreferences.getMediaAccessStatus("camera"),
+ };
+ }
+
+ return { success: true, granted: false, status };
+ } catch (error) {
+ console.error("Failed to request camera access:", error);
+ return {
+ success: false,
+ granted: false,
+ status: "unknown",
+ error: String(error),
+ };
+ }
+ });
+
ipcMain.handle("open-source-selector", () => {
const sourceSelectorWin = getSourceSelectorWindow();
if (sourceSelectorWin) {
diff --git a/electron/main.ts b/electron/main.ts
index 23bcc492a..86d4e370b 100644
--- a/electron/main.ts
+++ b/electron/main.ts
@@ -333,12 +333,12 @@ app.on("activate", () => {
app.whenReady().then(async () => {
// Allow microphone/media permission checks
session.defaultSession.setPermissionCheckHandler((_webContents, permission) => {
- const allowed = ["media", "audioCapture", "microphone"];
+ const allowed = ["media", "audioCapture", "microphone", "videoCapture", "camera"];
return allowed.includes(permission);
});
session.defaultSession.setPermissionRequestHandler((_webContents, permission, callback) => {
- const allowed = ["media", "audioCapture", "microphone"];
+ const allowed = ["media", "audioCapture", "microphone", "videoCapture", "camera"];
callback(allowed.includes(permission));
});
diff --git a/electron/preload.ts b/electron/preload.ts
index b91837729..ac9451d21 100644
--- a/electron/preload.ts
+++ b/electron/preload.ts
@@ -27,6 +27,9 @@ contextBridge.exposeInMainWorld("electronAPI", {
getSelectedSource: () => {
return ipcRenderer.invoke("get-selected-source");
},
+ requestCameraAccess: () => {
+ return ipcRenderer.invoke("request-camera-access");
+ },
storeRecordedVideo: (videoData: ArrayBuffer, fileName: string) => {
return ipcRenderer.invoke("store-recorded-video", videoData, fileName);
diff --git a/src/components/launch/LaunchWindow.tsx b/src/components/launch/LaunchWindow.tsx
index bca5d4a2d..4bf6df8c5 100644
--- a/src/components/launch/LaunchWindow.tsx
+++ b/src/components/launch/LaunchWindow.tsx
@@ -248,7 +248,11 @@ export function LaunchWindow() {
</button>
<button
className={`${hudIconBtnClasses} ${webcamEnabled ? "drop-shadow-[0_0_4px_rgba(74,222,128,0.4)]" : ""}`}
- onClick={() => !recording && setWebcamEnabled(!webcamEnabled)}
+ onClick={() => {
+ if (!recording) {
+ void setWebcamEnabled(!webcamEnabled);
+ }
+ }}
disabled={recording}
title={webcamEnabled ? "Disable webcam" : "Enable webcam"}
>
diff --git a/src/components/video-editor/VideoPlayback.tsx b/src/components/video-editor/VideoPlayback.tsx
index d939b47d7..c63c871ec 100644
--- a/src/components/video-editor/VideoPlayback.tsx
+++ b/src/components/video-editor/VideoPlayback.tsx
@@ -968,6 +968,13 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
return;
}
+ const activeSpeedRegion =
+ speedRegions.find(
+ (region) =>
+ currentTime * 1000 >= region.startMs && currentTime * 1000 < region.endMs,
+ ) ?? null;
+ webcamVideo.playbackRate = activeSpeedRegion ? activeSpeedRegion.speed : 1;
+
if (!isPlaying) {
webcamVideo.pause();
if (Math.abs(webcamVideo.currentTime - currentTime) > 0.05) {
@@ -983,7 +990,7 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
webcamVideo.play().catch(() => {
// Ignore webcam autoplay restoration failures.
});
- }, [currentTime, isPlaying, webcamVideoPath]);
+ }, [currentTime, isPlaying, speedRegions, webcamVideoPath]);
useEffect(() => {
const webcamVideo = webcamVideoRef.current;
diff --git a/src/hooks/useScreenRecorder.ts b/src/hooks/useScreenRecorder.ts
index c186f2415..85225b71b 100644
--- a/src/hooks/useScreenRecorder.ts
+++ b/src/hooks/useScreenRecorder.ts
@@ -47,7 +47,7 @@ type UseScreenRecorderReturn = {
systemAudioEnabled: boolean;
setSystemAudioEnabled: (enabled: boolean) => void;
webcamEnabled: boolean;
- setWebcamEnabled: (enabled: boolean) => void;
+ setWebcamEnabled: (enabled: boolean) => Promise<boolean>;
};
type RecorderHandle = {
@@ -82,7 +82,7 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
const [microphoneEnabled, setMicrophoneEnabled] = useState(false);
const [microphoneDeviceId, setMicrophoneDeviceId] = useState<string | undefined>(undefined);
const [systemAudioEnabled, setSystemAudioEnabled] = useState(false);
- const [webcamEnabled, setWebcamEnabled] = useState(false);
+ const [webcamEnabled, setWebcamEnabledState] = useState(false);
const screenRecorder = useRef<RecorderHandle | null>(null);
const webcamRecorder = useRef<RecorderHandle | null>(null);
const stream = useRef<MediaStream | null>(null);
@@ -146,6 +146,38 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
}
}, []);
+ const setWebcamEnabled = useCallback(async (enabled: boolean) => {
+ if (!enabled) {
+ setWebcamEnabledState(false);
+ return true;
+ }
+
+ const accessResult = await window.electronAPI.requestCameraAccess();
+ if (!accessResult.success) {
+ toast.error("Failed to request camera access.");
+ return false;
+ }
+
+ if (!accessResult.granted) {
+ toast.error("Camera access is blocked. Enable it in system settings to use the webcam.");
+ return false;
+ }
+
+ try {
+ const probeStream = await navigator.mediaDevices.getUserMedia({
+ audio: false,
+ video: true,
+ });
+ probeStream.getTracks().forEach((track) => track.stop());
+ setWebcamEnabledState(true);
+ return true;
+ } catch (error) {
+ console.warn("Failed to preflight webcam access:", error);
+ toast.error("Camera access denied. Webcam overlay will stay disabled.");
+ return false;
+ }
+ }, []);
+
const stopRecording = useRef(() => {
const activeScreenRecorder = screenRecorder.current;
if (activeScreenRecorder?.recorder.state !== "recording") {
diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts
index 16bc9d319..1a1b28f89 100644
--- a/src/vite-env.d.ts
+++ b/src/vite-env.d.ts
@@ -22,6 +22,12 @@ interface Window {
openSourceSelector: () => Promise<void>;
selectSource: (source: ProcessedDesktopSource) => Promise<ProcessedDesktopSource | null>;
getSelectedSource: () => Promise<ProcessedDesktopSource | null>;
+ requestCameraAccess: () => Promise<{
+ success: boolean;
+ granted: boolean;
+ status: string;
+ error?: string;
+ }>;
storeRecordedVideo: (
videoData: ArrayBuffer,
fileName: string,