Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix YUYV on windows + cleanup
Brendan Allana56dda3304ee
diff --git a/crates/media/src/feeds/camera.rs b/crates/media/src/feeds/camera.rsindex 20bd60cc1..5ddb3a30e 100644--- a/crates/media/src/feeds/camera.rs+++ b/crates/media/src/feeds/camera.rs@@ -368,12 +368,19 @@ fn buffer_to_ffvideo(buffer: nokhwa::Buffer) -> FFVideo {}}),FrameFormat::YUYV => {- // let bytes = buffer.buffer().len() as f32;- // let ratio = bytes / (buffer.resolution().x() * buffer.resolution().y()) as f32;- // if ratio == 2.0+ // nokhwa moment+ let pix_fmt = if cfg!(windows) {+ Pixel::YUYV422+ } else {+ // let bytes = buffer.buffer().len() as f32;+ // let ratio = bytes / (buffer.resolution().x() * buffer.resolution().y()) as f32;+ // if ratio == 2.0++ // nokhwa merges yuvu420 and uyvy422 into the same format, we should probably distinguish them with the frame size+ Pixel::UYVY422+ };- // nokhwa merges yuvu420 and uyvy422 into the same format, we should probably distinguish them with the frame size- (Pixel::UYVY422, |frame, buffer| {+ (pix_fmt, |frame, buffer| {let width = frame.width() as usize;let height = frame.height() as usize;diff --git a/crates/media/src/platform/macos.rs b/crates/media/src/platform/macos.rsindex dcd652504..256cd720d 100644--- a/crates/media/src/platform/macos.rs+++ b/crates/media/src/platform/macos.rs@@ -377,8 +377,6 @@ pub fn primary_monitor_bounds() -> Bounds {let width = display.pixels_wide();let bounds = unsafe { CGDisplayBounds(display.id) };- dbg!(bounds);-Bounds {x: bounds.origin.x,y: bounds.origin.y,diff --git a/crates/media/src/platform/win.rs b/crates/media/src/platform/win.rsindex 78cdd7239..36f0b5a5b 100644--- a/crates/media/src/platform/win.rs+++ b/crates/media/src/platform/win.rs@@ -270,10 +270,6 @@ pub fn monitor_bounds(id: u32) -> Bounds {if id == *target_id {let rect = minfo.monitorInfo.rcMonitor;- debug!(- "Found monitor with ID {}: bounds: left={}, top={}, right={}, bottom={}",- id, rect.left, rect.top, rect.right, rect.bottom- );*bounds = Some(Bounds {x: rect.left as f64,y: rect.top as f64,diff --git a/crates/rendering/src/decoder/ffmpeg.rs b/crates/rendering/src/decoder/ffmpeg.rsindex 1c6b371cc..b24141a81 100644--- a/crates/rendering/src/decoder/ffmpeg.rs+++ b/crates/rendering/src/decoder/ffmpeg.rs@@ -11,8 +11,8 @@ use ffmpeg::{};use ffmpeg_hw_device::{CodecContextExt, CodecExt, HwDevice};use ffmpeg_sys_next::{avcodec_find_decoder, AVHWDeviceType};-use tokio::sync::oneshot;use log::debug;+use tokio::sync::oneshot;use super::{pts_to_frame, DecodedFrame, VideoDecoderMessage, FRAME_CACHE_SIZE};@@ -118,16 +118,13 @@ impl FfmpegDecoder {}}- // Get video dimensions to check against hardware acceleration limitslet width = decoder.width();let height = decoder.height();- // Check if dimensions exceed common hardware decoder limitslet exceeds_common_hw_limits = width > 4096 || height > 4096;- debug!("Video dimensions: {}x{}", width, height);let mut hw_device = if exceeds_common_hw_limits {- debug!("Video dimensions {}x{} exceed common hardware decoder limits (4096x4096), disabling hardware acceleration", width, height);+ debug!("Video dimensions {width}x{height} exceed common hardware decoder limits (4096x4096), not using hardware acceleration");None} else {let hw_device_types = if cfg!(target_os = "macos") {@@ -146,29 +143,10 @@ impl FfmpegDecoder {hw_device_types.iter()- .find_map(|&typ| {- let type_name = match typ {- AVHWDeviceType::AV_HWDEVICE_TYPE_CUDA => "CUDA",- AVHWDeviceType::AV_HWDEVICE_TYPE_D3D12VA => "D3D12VA",- AVHWDeviceType::AV_HWDEVICE_TYPE_D3D11VA => "D3D11VA",- AVHWDeviceType::AV_HWDEVICE_TYPE_VAAPI => "VAAPI",- AVHWDeviceType::AV_HWDEVICE_TYPE_VULKAN => "VULKAN",- AVHWDeviceType::AV_HWDEVICE_TYPE_DXVA2 => "DXVA2",- AVHWDeviceType::AV_HWDEVICE_TYPE_VIDEOTOOLBOX => "VIDEOTOOLBOX",- _ => "Unknown",- };-- debug!("Trying hardware acceleration: {}", type_name);- let result = decoder.try_use_hw_device(typ);- if result.is_err() {- debug!("Failed to initialize {} hardware acceleration", type_name);- } else {- debug!("Successfully initialized {} hardware acceleration", type_name);- }- result.ok()- })+ .find_map(|&typ| decoder.try_use_hw_device(typ).ok())};-+ let hw_device = hw_device.as_ref();+if hw_device.is_none() && !exceeds_common_hw_limits {debug!("No hardware acceleration available, falling back to software decoding");}@@ -190,13 +168,8 @@ impl FfmpegDecoder {let mut peekable_requests = PeekableReceiver { rx, peeked: None };let mut packets = input.packets().peekable();-- // Track hardware acceleration failures to detect when we need to fall back- let mut hw_failure_count = 0;- let max_hw_failures = 5; // Maximum number of consecutive failures before falling back to software- let mut using_hw_acceleration = hw_device.is_some();- ready_tx.send(Ok(()));+ let _ = ready_tx.send(Ok(()));while let Ok(r) = peekable_requests.recv() {match r {@@ -237,7 +210,6 @@ impl FfmpegDecoder {decoder.flush();input.seek(position, ..position).unwrap();last_decoded_frame = None;- hw_failure_count = 0; // Reset failure count on seekpackets = input.packets().peekable();}@@ -263,48 +235,11 @@ impl FfmpegDecoder {if stream.index() == input_stream_index {let start_offset = stream.start_time();- // Try to send packet and detect repeated failures- let packet_result = decoder.send_packet(&packet);- if let Err(e) = packet_result {- debug!("Warning: Failed to decode packet: {:?}", e);-- // If we're using hardware acceleration and getting repeated errors- if using_hw_acceleration {- hw_failure_count += 1;-- // If we've hit our threshold of failures, disable hardware acceleration- if hw_failure_count >= max_hw_failures {- debug!("Detected repeated hardware acceleration failures. Falling back to software decoding.");-- // Disable hardware acceleration- using_hw_acceleration = false;- hw_device = None;-- // Recreate decoder with software-only- decoder.flush();-- // Reset counters and try again- hw_failure_count = 0;-- // Seek back to reset the stream- let timestamp_us = ((requested_frame as f32 / frame_rate.numerator() as f32) * 1_000_000.0) as i64;- let position = timestamp_us.rescale((1, 1_000_000), rescale::TIME_BASE);- input.seek(position, ..position).unwrap();- packets = input.packets().peekable();- continue;- }- }- } else {- // Successful packet decode, reset failure counter- hw_failure_count = 0;- }+ let _ = decoder.send_packet(&packet);let mut exit = false;while decoder.receive_frame(&mut temp_frame).is_ok() {- // Successful frame received, reset failure counter- hw_failure_count = 0;-let current_frame = pts_to_frame(temp_frame.pts().unwrap() - start_offset,time_base,@@ -333,17 +268,12 @@ impl FfmpegDecoder {let exceeds_cache_bounds = current_frame > cache_max;let too_small_for_cache_bounds = current_frame < cache_min;- let hw_frame =- if using_hw_acceleration {- hw_device.as_ref().and_then(|d| d.get_hwframe(&temp_frame))- } else {- None- };-- let frame = hw_frame.unwrap_or(std::mem::replace(- &mut temp_frame,- frame::Video::empty(),- ));+ let frame = hw_device+ .and_then(|d| d.get_hwframe(&temp_frame))+ .unwrap_or(std::mem::replace(+ &mut temp_frame,+ frame::Video::empty(),+ ));if !too_small_for_cache_bounds {let mut cache_frame = CachedFrame {