Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

update nokhwa (#334)

Brendan Allana7d55bfe19d6
diff --git a/.gitignore b/.gitignore
index a32642b5b..eaa4d220b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,3 +37,4 @@ native-deps*
apps/storybook/storybook-static
*.tsbuildinfo
+.cargo/config.toml
diff --git a/Cargo.lock b/Cargo.lock
index bc82dc85b..e36764fcb 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1163,6 +1163,14 @@ dependencies = [
"windows-sys 0.52.0",
]
+[[package]]
+name = "cap-video-decode"
+version = "0.1.0"
+dependencies = [
+ "ffmpeg-next",
+ "ffmpeg-sys-next",
+]
+
[[package]]
name = "cargo-platform"
version = "0.1.8"
@@ -4402,7 +4410,7 @@ checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
[[package]]
name = "nokhwa"
version = "0.10.3"
-source = "git+https://github.com/CapSoftware/nokhwa?rev=d37141b1883d#d37141b1883d7250f7d2ccc9bc199ecaee48d51b"
+source = "git+https://github.com/CapSoftware/nokhwa?rev=e309b938ccd6#e309b938ccd6d17afac4017b11e7bda9f6cd9f35"
dependencies = [
"flume 0.10.14",
"image 0.24.9",
@@ -4418,7 +4426,7 @@ dependencies = [
[[package]]
name = "nokhwa-bindings-linux"
version = "0.1.0"
-source = "git+https://github.com/CapSoftware/nokhwa?rev=d37141b1883d#d37141b1883d7250f7d2ccc9bc199ecaee48d51b"
+source = "git+https://github.com/CapSoftware/nokhwa?rev=e309b938ccd6#e309b938ccd6d17afac4017b11e7bda9f6cd9f35"
dependencies = [
"nokhwa-core",
"v4l",
@@ -4428,7 +4436,7 @@ dependencies = [
[[package]]
name = "nokhwa-bindings-macos"
version = "0.2.0"
-source = "git+https://github.com/CapSoftware/nokhwa?rev=d37141b1883d#d37141b1883d7250f7d2ccc9bc199ecaee48d51b"
+source = "git+https://github.com/CapSoftware/nokhwa?rev=e309b938ccd6#e309b938ccd6d17afac4017b11e7bda9f6cd9f35"
dependencies = [
"block",
"cocoa-foundation 0.1.2",
@@ -4443,7 +4451,7 @@ dependencies = [
[[package]]
name = "nokhwa-bindings-windows"
version = "0.4.0"
-source = "git+https://github.com/CapSoftware/nokhwa?rev=d37141b1883d#d37141b1883d7250f7d2ccc9bc199ecaee48d51b"
+source = "git+https://github.com/CapSoftware/nokhwa?rev=e309b938ccd6#e309b938ccd6d17afac4017b11e7bda9f6cd9f35"
dependencies = [
"nokhwa-core",
"once_cell",
@@ -4453,7 +4461,7 @@ dependencies = [
[[package]]
name = "nokhwa-core"
version = "0.1.0"
-source = "git+https://github.com/CapSoftware/nokhwa?rev=d37141b1883d#d37141b1883d7250f7d2ccc9bc199ecaee48d51b"
+source = "git+https://github.com/CapSoftware/nokhwa?rev=e309b938ccd6#e309b938ccd6d17afac4017b11e7bda9f6cd9f35"
dependencies = [
"bytes",
"image 0.24.9",
diff --git a/Cargo.toml b/Cargo.toml
index 101efebc9..c932dd34e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -22,11 +22,11 @@ tauri = { version = "2.2.3", features = ["specta"] }
specta = { version = "=2.0.0-rc.20", features = ["derive", "uuid"] }
scap = { git = "https://github.com/CapSoftware/scap", rev = "58d4410bf52f" }
-nokhwa = { git = "https://github.com/CapSoftware/nokhwa", rev = "d37141b1883d", features = [
+nokhwa = { git = "https://github.com/CapSoftware/nokhwa", rev = "e309b938ccd6", features = [
"input-native",
"serialize",
] }
-nokhwa-bindings-macos = { git = "https://github.com/CapSoftware/nokhwa", rev = "d37141b1883d" }
+nokhwa-bindings-macos = { git = "https://github.com/CapSoftware/nokhwa", rev = "e309b938ccd6" }
wgpu = "22.1.0"
flume = "0.11.0"
thiserror = "1.0"
diff --git a/crates/video-decode/Cargo.toml b/crates/video-decode/Cargo.toml
new file mode 100644
index 000000000..c63d6dd86
--- /dev/null
+++ b/crates/video-decode/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "cap-video-decode"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
+ffmpeg.workspace = true
+ffmpeg-sys-next.workspace = true
diff --git a/crates/video-decode/src/main.rs b/crates/video-decode/src/main.rs
new file mode 100644
index 000000000..288596573
--- /dev/null
+++ b/crates/video-decode/src/main.rs
@@ -0,0 +1,65 @@
+fn main() {
+ let path = "/Users/brendonovich/Library/Application Support/so.cap.desktop.dev/recordings/51ecf128-913e-456c-8959-c73c6c4a60b3.cap/content/segments/segment-0/display.mp4";
+
+ let mut input = ffmpeg::format::input(&path).unwrap();
+
+ let input_stream = input
+ .streams()
+ .best(ffmpeg::media::Type::Video)
+ .ok_or("Could not find a video stream")
+ .unwrap();
+
+ let decoder_codec =
+ find_decoder(&input, &input_stream, input_stream.parameters().id()).unwrap();
+
+ let mut context = ffmpeg::codec::context::Context::new_with_codec(decoder_codec);
+ context.set_parameters(input_stream.parameters()).unwrap();
+
+ let input_stream_index = input_stream.index();
+ let time_base = input_stream.time_base();
+ let frame_rate = input_stream.rate();
+
+ // Create a decoder for the video stream
+ let mut decoder = context.decoder().video().unwrap();
+
+ let mut temp_frame = ffmpeg::frame::Video::empty();
+
+ for (stream, packet) in input.packets() {
+ if stream.index() == input_stream_index {
+ decoder.send_packet(&packet).unwrap();
+
+ while decoder.receive_frame(&mut temp_frame).is_ok() {
+ dbg!(temp_frame.pts());
+ }
+ }
+ }
+}
+
+pub fn find_decoder(
+ s: &ffmpeg::format::context::Input,
+ st: &ffmpeg::format::stream::Stream,
+ codec_id: ffmpeg::codec::Id,
+) -> Option<ffmpeg::Codec> {
+ unsafe {
+ use ffmpeg::media::Type;
+ let codec = match st.parameters().medium() {
+ Type::Video => Some((*s.as_ptr()).video_codec),
+ Type::Audio => Some((*s.as_ptr()).audio_codec),
+ Type::Subtitle => Some((*s.as_ptr()).subtitle_codec),
+ _ => None,
+ };
+
+ if let Some(codec) = codec {
+ if !codec.is_null() {
+ return Some(ffmpeg::Codec::wrap(codec));
+ }
+ }
+
+ let found = ffmpeg::sys::avcodec_find_decoder(codec_id.into());
+
+ if found.is_null() {
+ return None;
+ }
+ Some(ffmpeg::Codec::wrap(found))
+ }
+}