Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Ensure even dimensions for screen capture sizes

Richie McIlroy25c2c9559aad
diff --git a/crates/recording/src/sources/screen_capture/macos.rs b/crates/recording/src/sources/screen_capture/macos.rs
index a5322af97..6eeb8f047 100644
--- a/crates/recording/src/sources/screen_capture/macos.rs
+++ b/crates/recording/src/sources/screen_capture/macos.rs
@@ -140,7 +140,9 @@ impl ScreenCaptureConfig<CMSampleBufferCapture> {
let scale =
display.physical_size().unwrap().width() / display.logical_size().unwrap().width();
- PhysicalSize::new(logical_size.width() * scale, logical_size.height() * scale)
+ let width = ensure_even((logical_size.width() * scale) as u32) as f64;
+ let height = ensure_even((logical_size.height() * scale) as u32) as f64;
+ PhysicalSize::new(width, height)
};
debug!("size: {:?}", size);
diff --git a/crates/recording/src/sources/screen_capture/mod.rs b/crates/recording/src/sources/screen_capture/mod.rs
index da0a4b90b..2e106f048 100644
--- a/crates/recording/src/sources/screen_capture/mod.rs
+++ b/crates/recording/src/sources/screen_capture/mod.rs
@@ -1,5 +1,5 @@
use cap_cursor_capture::CursorCropBounds;
-use cap_media_info::{AudioInfo, VideoInfo};
+use cap_media_info::{AudioInfo, VideoInfo, ensure_even};
use scap_targets::{Display, DisplayId, Window, WindowId, bounds::*};
use serde::{Deserialize, Serialize};
use specta::Type;
@@ -311,10 +311,9 @@ impl<TCaptureFormat: ScreenCaptureFormat> ScreenCaptureConfig<TCaptureFormat> {
crop_bounds.and_then(|b| {
let logical_size = b.size();
let scale = display.raw_handle().scale()?;
- Some(PhysicalSize::new(
- logical_size.width() * scale,
- logical_size.height() * scale,
- ))
+ let width = ensure_even((logical_size.width() * scale) as u32) as f64;
+ let height = ensure_even((logical_size.height() * scale) as u32) as f64;
+ Some(PhysicalSize::new(width, height))
})
}