Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix hardware decode

Brendan Allan7ce047149cd5
diff --git a/apps/desktop/scripts/prepare.js b/apps/desktop/scripts/prepare.js
index 04e8e17d6..8b5459e06 100644
--- a/apps/desktop/scripts/prepare.js
+++ b/apps/desktop/scripts/prepare.js
@@ -33,9 +33,8 @@ async function semverToWIXCompatibleVersion(cargoFilePath) {
const numMatch = buildOrPrerelease.match(/\d+$/);
build = numMatch ? parseInt(numMatch[0]) : 0;
}
- const wixVersion = `${major}.${minor}.${patch}${
- build === 0 ? "" : `.${build}`
- }`;
+ const wixVersion = `${major}.${minor}.${patch}${build === 0 ? "" : `.${build}`
+ }`;
if (wixVersion !== ver)
console.log(`Using wix-compatible version ${ver} --> ${wixVersion}`);
return wixVersion;
@@ -80,7 +79,9 @@ export async function createTauriPlatformConfigs(
baseConfig = {
...baseConfig,
bundle: {
- "../../../target/ffmpeg/bin/*.dll": "./",
+ resources: {
+ "../../../target/ffmpeg/bin/*.dll": "./",
+ },
windows: {
wix: {
version: await semverToWIXCompatibleVersion(
diff --git a/apps/desktop/src-tauri/tauri.windows.conf.json b/apps/desktop/src-tauri/tauri.windows.conf.json
index ae452e95b..24bf6f9dc 100644
--- a/apps/desktop/src-tauri/tauri.windows.conf.json
+++ b/apps/desktop/src-tauri/tauri.windows.conf.json
@@ -1,10 +1,12 @@
{
"bundle": {
+ "resources": {
+ "../../../target/ffmpeg/bin/*.dll": "./"
+ },
"windows": {
- "../../../target/ffmpeg/bin/*.dll": "./",
"wix": {
"version": "0.3.26"
}
}
}
-}
+}
\ No newline at end of file
diff --git a/crates/ffmpeg-hw-device/src/lib.rs b/crates/ffmpeg-hw-device/src/lib.rs
index cb8ee41bd..91b766e49 100644
--- a/crates/ffmpeg-hw-device/src/lib.rs
+++ b/crates/ffmpeg-hw-device/src/lib.rs
@@ -41,7 +41,6 @@ unsafe extern "C" fn get_format(
pub struct HwDevice {
pub device_type: AVHWDeviceType,
- pub pix_fmt: Pixel,
ctx: *mut AVBufferRef,
}
@@ -70,36 +69,22 @@ impl Drop for HwDevice {
}
pub trait CodecContextExt {
- fn try_use_hw_device(
- &mut self,
- device_type: AVHWDeviceType,
- pix_fmt: Pixel,
- ) -> Result<HwDevice, &'static str>;
+ fn try_use_hw_device(&mut self, device_type: AVHWDeviceType) -> Result<HwDevice, &'static str>;
}
impl CodecContextExt for codec::decoder::decoder::Decoder {
- fn try_use_hw_device(
- &mut self,
- device_type: AVHWDeviceType,
- pix_fmt: Pixel,
- ) -> Result<HwDevice, &'static str> {
+ fn try_use_hw_device(&mut self, device_type: AVHWDeviceType) -> Result<HwDevice, &'static str> {
let codec = self.codec().ok_or("no codec")?;
unsafe {
- let mut i = 0;
- loop {
- let config = avcodec_get_hw_config(codec.as_ptr(), i);
- if config.is_null() {
- return Err("no hw config");
- }
-
- if (*config).methods & (AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX as i32) == 1 {
- HW_PIX_FMT.set((*config).pix_fmt);
- break;
- }
-
- i += 1;
- }
+ let Some(hw_config) = codec.hw_configs().find(|&config| {
+ (*config).device_type == device_type
+ && (*config).methods & (AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX as i32) == 1
+ }) else {
+ return Err("no hw config");
+ };
+
+ HW_PIX_FMT.set((*hw_config).pix_fmt);
let context = self.as_mut_ptr();
@@ -116,7 +101,6 @@ impl CodecContextExt for codec::decoder::decoder::Decoder {
Ok(HwDevice {
device_type,
ctx: hw_device_ctx,
- pix_fmt,
})
}
}
diff --git a/crates/flags/src/lib.rs b/crates/flags/src/lib.rs
index 32e7eb358..5c5ef4edc 100644
--- a/crates/flags/src/lib.rs
+++ b/crates/flags/src/lib.rs
@@ -6,6 +6,6 @@ pub struct Flags {
}
pub const FLAGS: Flags = Flags {
- record_mouse_state: false, // cfg!(debug_assertions),
+ record_mouse_state: cfg!(debug_assertions),
split: false,
};
diff --git a/crates/rendering/src/decoder/ffmpeg.rs b/crates/rendering/src/decoder/ffmpeg.rs
index 826a27ec3..951106d4b 100644
--- a/crates/rendering/src/decoder/ffmpeg.rs
+++ b/crates/rendering/src/decoder/ffmpeg.rs
@@ -123,55 +123,23 @@ impl FfmpegDecoder {
}
}
- let hw_device: Option<HwDevice> = if cfg!(target_os = "macos") {
- decoder
- .try_use_hw_device(AVHWDeviceType::AV_HWDEVICE_TYPE_VIDEOTOOLBOX, Pixel::NV12)
- .ok()
- } else if cfg!(target_os = "windows") {
- // For now, disable hardware acceleration on Windows as it's causing issues
- // This ensures reliable playback while we debug the hardware acceleration issues
- None
-
- // Uncomment the below code once hardware acceleration issues are resolved
- /*
- // Try D3D11VA first - most widely supported on modern Windows
- let d3d11va = decoder
- .try_use_hw_device(AVHWDeviceType::AV_HWDEVICE_TYPE_D3D11VA, Pixel::D3D11)
- .ok();
-
- if d3d11va.is_some() {
- println!("Using D3D11VA hardware acceleration");
- d3d11va
- } else {
- // Try CUDA for NVIDIA GPUs
- let cuda = decoder
- .try_use_hw_device(AVHWDeviceType::AV_HWDEVICE_TYPE_CUDA, Pixel::CUDA)
- .ok();
-
- if cuda.is_some() {
- println!("Using CUDA hardware acceleration");
- cuda
- } else {
- // Try QSV for Intel GPUs
- let qsv = decoder
- .try_use_hw_device(AVHWDeviceType::AV_HWDEVICE_TYPE_QSV, Pixel::QSV)
- .ok();
-
- if qsv.is_some() {
- println!("Using QSV hardware acceleration");
- qsv
- } else {
- println!("Falling back to software decoding");
- None
- }
- }
- }
- */
+ let hw_device_types = if cfg!(target_os = "macos") {
+ [AVHWDeviceType::AV_HWDEVICE_TYPE_VIDEOTOOLBOX].as_slice()
} else {
- None
+ [
+ AVHWDeviceType::AV_HWDEVICE_TYPE_CUDA,
+ AVHWDeviceType::AV_HWDEVICE_TYPE_D3D12VA,
+ AVHWDeviceType::AV_HWDEVICE_TYPE_D3D11VA,
+ AVHWDeviceType::AV_HWDEVICE_TYPE_VAAPI,
+ AVHWDeviceType::AV_HWDEVICE_TYPE_VULKAN,
+ AVHWDeviceType::AV_HWDEVICE_TYPE_DXVA2,
+ ]
+ .as_slice()
};
- use ffmpeg::format::Pixel;
+ let hw_device = hw_device_types
+ .iter()
+ .find_map(|&typ| decoder.try_use_hw_device(typ).ok());
let mut temp_frame = ffmpeg::frame::Video::empty();
@@ -230,6 +198,7 @@ impl FfmpegDecoder {
* 1_000_000.0) as i64;
let position = timestamp_us.rescale((1, 1_000_000), rescale::TIME_BASE);
+ println!("seeking to {}", position);
decoder.flush();
input.seek(position, ..position).unwrap();
last_decoded_frame = None;