Skip to content

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

Merge remote-tracking branch 'origin/main' into codex/fix-windows-paused-recording

Siddhartha50835e30f5a
diff --cc electron/native/wgc-capture/src/main.cpp
index 24bab84d8,7968d94a4..bb741d33e
--- a/electron/native/wgc-capture/src/main.cpp
+++ b/electron/native/wgc-capture/src/main.cpp
@@@ -512,8 -470,27 +516,26 @@@ int main(int argc, char* argv[])
return 1;
}
+ MFEncoder webcamEncoder;
+ if (writeSeparateWebcam) {
+ const int webcamPixels = std::max(1, webcamCapture.width()) * std::max(1, webcamCapture.height());
+ const int webcamBitrate = webcamPixels >= 1280 * 720 ? 8'000'000 : 4'000'000;
+ if (!webcamEncoder.initialize(
+ utf8ToWide(config.webcamOutputPath),
+ webcamCapture.width(),
+ webcamCapture.height(),
+ webcamCapture.fps(),
+ webcamBitrate,
+ session.device(),
+ session.context(),
+ nullptr)) {
+ std::cerr << "ERROR: Failed to initialize native webcam encoder" << std::endl;
+ return 1;
+ }
+ }
+
std::mutex mutex;
- std::condition_variable cv;
- std::atomic<bool> stopRequested = false;
+ CaptureControl control;
std::atomic<bool> firstFrameWritten = false;
std::atomic<bool> encodeFailed = false;
Microsoft::WRL::ComPtr<ID3D11Texture2D> latestFrameTexture;
@@@ -552,31 -530,24 +575,33 @@@
});
auto writeVideoFrames = [&]() {
- const auto startedAt = std::chrono::steady_clock::now();
+ const auto frameDuration = std::chrono::duration_cast<std::chrono::steady_clock::duration>(
+ std::chrono::duration<double>(1.0 / config.fps));
uint64_t frameIndex = 0;
+ uint64_t lastWrittenWebcamSequence = 0;
+ uint64_t webcamOutputFrameIndex = 0;
int64_t lastEncodedVideoTimestampHns = -1;
- while (!stopRequested && !encodeFailed) {
+ while (!control.stopRequested && !encodeFailed) {
{
- std::scoped_lock lock(mutex);
+ std::unique_lock lock(mutex);
+ control.cv.wait(lock, [&] {
+ return control.stopRequested.load() ||
+ encodeFailed.load() ||
+ (!control.paused.load() && latestFrameTexture);
+ });
+ if (control.stopRequested || encodeFailed) {
+ break;
+ }
if (webcamActive) {
- std::vector<BYTE> candidateWebcamFrame;
- int candidateWebcamWidth = 0;
- int candidateWebcamHeight = 0;
- if (webcamCapture.copyLatestFrame(candidateWebcamFrame, candidateWebcamWidth, candidateWebcamHeight) &&
- hasVisibleBgraContent(candidateWebcamFrame)) {
- latestWebcamFrame = std::move(candidateWebcamFrame);
- latestWebcamWidth = candidateWebcamWidth;
- latestWebcamHeight = candidateWebcamHeight;
+ WebcamFrameSnapshot candidateWebcamFrame;
+ if (webcamCapture.copyLatestFrame(candidateWebcamFrame) &&
+ candidateWebcamFrame.sequence != latestWebcamSequence &&
+ hasVisibleBgraContent(candidateWebcamFrame.data)) {
+ latestWebcamFrame = std::move(candidateWebcamFrame.data);
+ latestWebcamWidth = candidateWebcamFrame.width;
+ latestWebcamHeight = candidateWebcamFrame.height;
+ latestWebcamSequence = candidateWebcamFrame.sequence;
hasVisibleWebcamFrame = true;
}
}
@@@ -604,10 -586,10 +642,10 @@@
if (latestFrameTexture && !encoder.writeFrame(
latestFrameTexture.Get(),
frameTimestampHns,
- webcamFrame.data ? &webcamFrame : nullptr)) {
+ !writeSeparateWebcam && webcamFrame.data ? &webcamFrame : nullptr)) {
encodeFailed = true;
- stopRequested = true;
- cv.notify_all();
+ control.stopRequested = true;
+ control.cv.notify_all();
return;
}
if (latestFrameTexture) {
diff --cc src/hooks/useScreenRecorder.ts
index 7abed3ac9,08d062ca4..14e55b359
--- a/src/hooks/useScreenRecorder.ts
+++ b/src/hooks/useScreenRecorder.ts
@@@ -84,7 -82,7 +82,8 @@@ type RecorderHandle =
type NativeWindowsRecordingHandle = {
recordingId: number;
finalizing: boolean;
+ paused: boolean;
+ webcamRecorder: RecorderHandle | null;
};
type NativeMacRecordingHandle = {
@@@ -796,8 -875,9 +876,10 @@@ export function useScreenRecorder(): Us
nativeWindowsRecording.current = {
recordingId: result.recordingId,
finalizing: false,
+ paused: false,
+ webcamRecorder: browserWebcamRecorder,
};
+ webcamRecorder.current = browserWebcamRecorder;
accumulatedDurationMs.current = 0;
segmentStartedAt.current = Date.now();
allowAutoFinalize.current = true;
@@@ -909,8 -989,8 +991,8 @@@
enabled: webcamEnabled,
deviceId: webcamDeviceId,
deviceName: webcamDeviceName,
-- width: WEBCAM_TARGET_WIDTH,
-- height: WEBCAM_TARGET_HEIGHT,
++ width: 0,
++ height: 0,
fps: WEBCAM_TARGET_FRAME_RATE,
},
cursor: {