Skip to content

Create polished demo videos without editing skills. Mac/Windows/Linux

fix(recording): validate native captures and tighten mic menu spacing

webadderalld485c0b2260f
diff --git a/electron/ipc/handlers.ts b/electron/ipc/handlers.ts
index b5fdcbac..16a265e2 100644
--- a/electron/ipc/handlers.ts
+++ b/electron/ipc/handlers.ts
@@ -1722,10 +1722,6 @@ function waitForWindowsCaptureStop(proc: ChildProcessWithoutNullStreams) {
resolve(match[1].trim())
return
}
- if (code === 0 && windowsCaptureTargetPath) {
- resolve(windowsCaptureTargetPath)
- return
- }
reject(new Error(windowsCaptureOutputBuffer.trim() || `Native Windows capture exited with code ${code ?? 'unknown'}`))
}
@@ -1847,6 +1843,43 @@ async function muxNativeWindowsVideoWithAudio(videoPath: string, systemAudioPath
}
}
+async function probeRecordedMediaStream(videoPath: string, streamType: 'video' | 'audio') {
+ const ffmpegPath = getFfmpegBinaryPath()
+ const args = streamType === 'video'
+ ? ['-v', 'error', '-i', videoPath, '-map', '0:v:0', '-frames:v', '1', '-f', 'null', '-']
+ : ['-v', 'error', '-i', videoPath, '-map', '0:a:0', '-frames:a', '1', '-f', 'null', '-']
+
+ await execFileAsync(ffmpegPath, args, {
+ timeout: 30000,
+ maxBuffer: 4 * 1024 * 1024,
+ })
+}
+
+async function validateRecordedVideoFile(videoPath: string, options?: { requiresAudio?: boolean }) {
+ await fs.access(videoPath, fsConstants.R_OK)
+
+ const stats = await fs.stat(videoPath)
+ if (stats.size <= 0) {
+ throw new Error('Recorded video file is empty')
+ }
+
+ try {
+ await probeRecordedMediaStream(videoPath, 'video')
+ } catch (error) {
+ throw new Error(`Recorded video file is unreadable or missing a video stream: ${String(error)}`)
+ }
+
+ if (!options?.requiresAudio) {
+ return
+ }
+
+ try {
+ await probeRecordedMediaStream(videoPath, 'audio')
+ } catch (error) {
+ throw new Error(`Recorded video is missing the requested audio track: ${String(error)}`)
+ }
+}
+
function waitForNativeCaptureStart(process: ChildProcessWithoutNullStreams) {
return new Promise<void>((resolve, reject) => {
const timer = setTimeout(() => {
@@ -2445,6 +2478,7 @@ function snapshotCursorTelemetryForPersistence() {
}
async function finalizeStoredVideo(videoPath: string) {
+ await validateRecordedVideoFile(videoPath)
snapshotCursorTelemetryForPersistence()
currentVideoPath = videoPath
currentProjectPath = null
@@ -3207,6 +3241,7 @@ body{background:transparent;overflow:hidden;width:100vw;height:100vh}
await moveFileWithOverwrite(tempVideoPath, finalVideoPath)
}
+ await validateRecordedVideoFile(finalVideoPath)
windowsPendingVideoPath = finalVideoPath
return { success: true, path: finalVideoPath }
} catch (error) {
@@ -3273,14 +3308,13 @@ body{background:transparent;overflow:hidden;width:100vw;height:100vh}
await moveFileWithOverwrite(tempVideoPath, finalVideoPath)
}
- if (preferredSystemAudioPath || preferredMicrophonePath) {
- try {
- await muxNativeMacRecordingWithAudio(finalVideoPath, preferredSystemAudioPath, preferredMicrophonePath)
- } catch (error) {
- console.warn('Failed to mux native macOS audio into capture:', error)
- }
+ const requiresAudio = Boolean(preferredSystemAudioPath || preferredMicrophonePath)
+
+ if (requiresAudio) {
+ await muxNativeMacRecordingWithAudio(finalVideoPath, preferredSystemAudioPath, preferredMicrophonePath)
}
+ await validateRecordedVideoFile(finalVideoPath, { requiresAudio })
return await finalizeStoredVideo(finalVideoPath)
} catch (error) {
console.error('Failed to stop native ScreenCaptureKit recording:', error)
@@ -3414,22 +3448,21 @@ body{background:transparent;overflow:hidden;width:100vw;height:100vh}
}
try {
- if (windowsSystemAudioPath || windowsMicAudioPath) {
+ const requiresAudio = Boolean(windowsSystemAudioPath || windowsMicAudioPath)
+
+ if (requiresAudio) {
await muxNativeWindowsVideoWithAudio(videoPath, windowsSystemAudioPath, windowsMicAudioPath)
windowsSystemAudioPath = null
windowsMicAudioPath = null
}
+ await validateRecordedVideoFile(videoPath, { requiresAudio })
return await finalizeStoredVideo(videoPath)
} catch (error) {
console.error('Failed to mux native Windows recording:', error)
windowsSystemAudioPath = null
windowsMicAudioPath = null
- try {
- return await finalizeStoredVideo(videoPath)
- } catch {
- return { success: false, message: 'Failed to mux native Windows recording', error: String(error) }
- }
+ return { success: false, message: 'Failed to mux native Windows recording', error: String(error) }
}
})
diff --git a/electron/native/wgc-capture/src/main.cpp b/electron/native/wgc-capture/src/main.cpp
index dd80bee2..a0f24d71 100644
--- a/electron/native/wgc-capture/src/main.cpp
+++ b/electron/native/wgc-capture/src/main.cpp
@@ -226,6 +226,7 @@ int main(int argc, char* argv[]) {
// Set up frame callback
std::atomic<int64_t> frameCount{0};
+ std::atomic<bool> frameWriteFailed{false};
session.setFrameCallback([&](ID3D11Texture2D* texture, int64_t timestampHns) {
g_lastFrameTimestampHns = timestampHns;
if (g_stopRequested) return;
@@ -247,7 +248,12 @@ int main(int argc, char* argv[]) {
if (encoder.writeFrame(texture, adjustedTimestampHns)) {
frameCount++;
+ return;
}
+
+ frameWriteFailed = true;
+ g_stopRequested = true;
+ g_stopCv.notify_all();
});
// Start stdin listener
@@ -310,7 +316,20 @@ int main(int argc, char* argv[]) {
session.stopCapture();
if (audioActive) loopback.stop();
if (micActive) micCapture.stop();
- encoder.finalize();
+ if (frameWriteFailed.load()) {
+ std::cerr << "ERROR: Failed to encode one or more video frames" << std::endl;
+ return 1;
+ }
+
+ if (frameCount.load() <= 0) {
+ std::cerr << "ERROR: No video frames were written" << std::endl;
+ return 1;
+ }
+
+ if (!encoder.finalize()) {
+ std::cerr << "ERROR: Failed to finalize Media Foundation encoder" << std::endl;
+ return 1;
+ }
std::cout << "Recording stopped. Output path: " << config.outputPath << std::endl;
if (audioActive) {
diff --git a/src/components/launch/LaunchWindow.module.css b/src/components/launch/LaunchWindow.module.css
index bfa9de88..c8770a92 100644
--- a/src/components/launch/LaunchWindow.module.css
+++ b/src/components/launch/LaunchWindow.module.css
@@ -217,6 +217,14 @@
color: #6360f5;
}
+.ddSeparator {
+ width: 100%;
+ height: 1px;
+ margin: 4px 0;
+ background: rgba(255, 255, 255, 0.07);
+ flex-shrink: 0;
+}
+
.recBtn {
position: relative;
width: 46px;
diff --git a/src/components/launch/LaunchWindow.tsx b/src/components/launch/LaunchWindow.tsx
index aa4f7c10..4889ee09 100644
--- a/src/components/launch/LaunchWindow.tsx
+++ b/src/components/launch/LaunchWindow.tsx
@@ -112,7 +112,7 @@ function DropdownItem({
}
function Separator() {
- return <div className={styles.sep} />;
+ return <div className={styles.ddSeparator} />;
}
function MicDeviceRow({
diff --git a/src/hooks/useScreenRecorder.ts b/src/hooks/useScreenRecorder.ts
index 5561b059..0120a732 100644
--- a/src/hooks/useScreenRecorder.ts
+++ b/src/hooks/useScreenRecorder.ts
@@ -168,11 +168,10 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
const selectMimeType = () => {
const preferred = [
- "video/webm;codecs=av1",
- "video/webm;codecs=h264",
"video/webm;codecs=vp9",
"video/webm;codecs=vp8",
"video/webm",
+ "video/webm;codecs=av1",
];
return preferred.find((type) => MediaRecorder.isTypeSupported(type)) ?? "video/webm";
@@ -402,7 +401,13 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
if (isNativeWindows) {
const muxResult = await window.electronAPI.muxNativeWindowsRecording();
- finalPath = muxResult?.path ?? result.path;
+ if (!muxResult?.success || !muxResult.path) {
+ console.error("Failed to finalize native Windows recording:", muxResult?.error ?? muxResult?.message);
+ alert("Recording could not be finalized because the captured video file is invalid.");
+ return;
+ }
+
+ finalPath = muxResult.path;
}
await finalizeRecordingSession(finalPath, webcamPath);