Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Revert "fix: Windows/Mac compatibility for webcam"

Richie McIlroy2ca852e00c4f
diff --git a/crates/media/src/feeds/camera.rs b/crates/media/src/feeds/camera.rs
index d9f23a3c0..f9be1bacb 100644
--- a/crates/media/src/feeds/camera.rs
+++ b/crates/media/src/feeds/camera.rs
@@ -356,23 +356,15 @@ impl FrameConverter {
camera_format.frame_rate(),
);
- // Create FFmpeg converter with platform-specific pixel format
- let initial_pixel_format = if camera_format.format() == FrameFormat::YUYV {
- #[cfg(target_os = "macos")]
- {
- ffmpeg::format::Pixel::UYVY422
- }
- #[cfg(not(target_os = "macos"))]
- {
- ffmpeg::format::Pixel::YUYV422
- }
- } else {
- video_info.pixel_format
- };
-
+ // Create FFmpeg converter
let context = ffmpeg::software::converter(
(video_info.width, video_info.height),
- initial_pixel_format,
+ if camera_format.format() == FrameFormat::YUYV {
+ // Try YUYV422 first, if that doesn't work the converter will be recreated with UYVY422
+ ffmpeg::format::Pixel::YUYV422
+ } else {
+ video_info.pixel_format
+ },
ffmpeg::format::Pixel::RGBA,
)
.unwrap();
@@ -390,55 +382,37 @@ impl FrameConverter {
match self.format {
FrameFormat::YUYV => {
- // Use platform-specific pixel format
- #[cfg(target_os = "macos")]
- let pixel_format = ffmpeg::format::Pixel::UYVY422;
- #[cfg(not(target_os = "macos"))]
- let pixel_format = ffmpeg::format::Pixel::YUYV422;
-
- // Create input frame with platform-specific format
- let mut input_frame =
- FFVideo::new(pixel_format, resolution.width(), resolution.height());
-
- let stride = resolution.width() as usize * 2;
- let src = buffer.buffer();
-
- // Copy data line by line
- {
- let dst_stride = input_frame.stride(0);
- let dst = input_frame.data_mut(0);
- for y in 0..resolution.height() as usize {
- let src_offset = y * stride;
- let dst_offset = y * dst_stride;
- dst[dst_offset..dst_offset + stride]
- .copy_from_slice(&src[src_offset..src_offset + stride]);
- }
- }
-
- // Create output frame
- let mut rgba_frame = FFVideo::new(
- ffmpeg::format::Pixel::RGBA,
- resolution.width(),
- resolution.height(),
- );
-
- // Convert the frame
- if self.context.run(&input_frame, &mut rgba_frame).is_ok() {
- rgba_frame.data(0).to_vec()
+ // Try converting with YUYV422 first
+ let result = self.convert_with_ffmpeg(buffer, resolution);
+
+ // If conversion fails (black/corrupted output), try with UYVY422
+ if result.iter().all(|&x| x == 0) {
+ // Recreate context with UYVY422
+ self.context = ffmpeg::software::converter(
+ (self.video_info.width, self.video_info.height),
+ ffmpeg::format::Pixel::UYVY422,
+ ffmpeg::format::Pixel::RGBA,
+ )
+ .unwrap();
+
+ // Try converting again with UYVY422
+ self.convert_with_ffmpeg(buffer, resolution)
} else {
- vec![0; (resolution.width() * resolution.height() * 4) as usize]
+ result
}
- }
+ },
_ => match &self.hw_converter {
- Some(HwConverter::NV12(converter)) => converter.convert(
- NV12Input::from_buffer(
- buffer.buffer(),
+ Some(HwConverter::NV12(converter)) => {
+ converter.convert(
+ NV12Input::from_buffer(
+ buffer.buffer(),
+ resolution.width(),
+ resolution.height(),
+ ),
resolution.width(),
resolution.height(),
- ),
- resolution.width(),
- resolution.height(),
- ),
+ )
+ }
_ => self.convert_with_ffmpeg(buffer, resolution),
},
}
diff --git a/package.json b/package.json
index 8067f8641..33c09c857 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"type": "module",
"scripts": {
"build": "dotenv -e .env -- turbo run build",
- "dev": "(RUST_BACKTRACE=1 cd apps/web && docker compose up -d && cd ../..) && dotenv -e .env -- pnpm --dir packages/database db:generate && dotenv -e .env -- pnpm --dir packages/database db:push && dotenv -e .env -- turbo run dev --filter=!@cap/storybook --no-cache --concurrency 12",
+ "dev": "(cd apps/web && docker compose up -d && cd ../..) && dotenv -e .env -- pnpm --dir packages/database db:generate && dotenv -e .env -- pnpm --dir packages/database db:push && dotenv -e .env -- turbo run dev --filter=!@cap/storybook --no-cache --concurrency 12",
"dev:manual": "dotenv -e .env -- turbo run dev --filter=!@cap/storybook --no-cache --concurrency 1",
"lint": "turbo run lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",