Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(desktop): properly use dxva2 for hardware decoding on windows (#1227)
Brendan Allan8f8a2225fd5e
diff --git a/crates/ffmpeg-hw-device/src/lib.rs b/crates/ffmpeg-hw-device/src/lib.rsindex 2cc314acb..899cf5474 100644--- a/crates/ffmpeg-hw-device/src/lib.rs+++ b/crates/ffmpeg-hw-device/src/lib.rs@@ -52,6 +52,7 @@ impl HwDevice {let mut sw_frame = frame::Video::empty();if av_hwframe_transfer_data(sw_frame.as_mut_ptr(), src.as_ptr(), 0) >= 0 {+ sw_frame.set_pts(src.pts());return Some(sw_frame);};}diff --git a/crates/rendering/src/decoder/ffmpeg.rs b/crates/rendering/src/decoder/ffmpeg.rsindex 53a7e6230..f2c299d5e 100644--- a/crates/rendering/src/decoder/ffmpeg.rs+++ b/crates/rendering/src/decoder/ffmpeg.rs@@ -52,18 +52,30 @@ impl FfmpegDecoder {rx: mpsc::Receiver<VideoDecoderMessage>,ready_tx: oneshot::Sender<Result<(), String>>,) -> Result<(), String> {- let mut this = cap_video_decode::FFmpegDecoder::new(- path,- Some(if cfg!(target_os = "macos") {- AVHWDeviceType::AV_HWDEVICE_TYPE_VIDEOTOOLBOX- } else {- AVHWDeviceType::AV_HWDEVICE_TYPE_D3D12VA- }),- )?;-- let time_base = this.decoder().time_base();- let start_time = this.start_time();+ let (continue_tx, continue_rx) = mpsc::channel();+std::thread::spawn(move || {+ let mut this = match cap_video_decode::FFmpegDecoder::new(+ path,+ Some(if cfg!(target_os = "macos") {+ AVHWDeviceType::AV_HWDEVICE_TYPE_VIDEOTOOLBOX+ } else {+ AVHWDeviceType::AV_HWDEVICE_TYPE_DXVA2+ }),+ ) {+ Err(e) => {+ let _ = continue_tx.send(Err(e));+ return;+ }+ Ok(v) => {+ let _ = continue_tx.send(Ok(()));+ v+ }+ };++ let time_base = this.decoder().time_base();+ let start_time = this.start_time();+let mut cache = BTreeMap::<u32, CachedFrame>::new();// active frame is a frame that triggered decode.// frames that are within render_more_margin of this frame won't trigger decode.@@ -229,6 +241,8 @@ impl FfmpegDecoder {}});+ continue_rx.recv().map_err(|e| e.to_string())??;+Ok(())}}diff --git a/crates/video-decode/src/ffmpeg.rs b/crates/video-decode/src/ffmpeg.rsindex 143b40637..3e981df50 100644--- a/crates/video-decode/src/ffmpeg.rs+++ b/crates/video-decode/src/ffmpeg.rs@@ -7,7 +7,7 @@ use ffmpeg::{};use ffmpeg_hw_device::{CodecContextExt, HwDevice};use std::path::PathBuf;-use tracing::debug;+use tracing::*;pub struct FFmpegDecoder {input: avformat::context::Input,@@ -52,15 +52,18 @@ impl FFmpegDecoder {let hw_device = hw_device_type.and_then(|hw_device_type| {if exceeds_common_hw_limits {- debug!(+ warn!("Video dimensions {width}x{height} exceed common hardware decoder limits (4096x4096), not using hardware acceleration");None} else {match decoder.try_use_hw_device(hw_device_type) {- Ok(device) => Some(device),+ Ok(device) => {+ debug!("Using hardware device");+ Some(device)+ },Err(error) => {- debug!("Failed to enable hardware decoder: {error:?}");+ error!("Failed to enable hardware decoder: {error:?}");None}}