Comments (11)
where do you call blocking_kind
method? the error is from there
from windows-capture.
Now, I'm getting different errors.
Can you tell me how to start the recording with a library? Which module or function is responsible for recording? How do I access them inside my main.rs
file to call it from the front end?
from windows-capture.
Now, I'm getting different errors.
Can you tell me how to start the recording with a library? Which module or function is responsible for recording? How do I access them inside my
main.rs
file to call it from the front end?
there is a example in readme
from windows-capture.
Hi, I'm also having problems in tauri, I literally copy and paste the init example and make it a fn and does not works, but my error is:
[2024-03-29][11:13:16][ERROR][komorebi_ui] Screen Capture Failed: FailedToInitWinRT
https://learn.microsoft.com/en-us/windows/win32/api/roapi/nf-roapi-roinitialize
use std::{
io::{self, Write},
time::Instant,
};
use windows::Win32::Foundation::HWND;
use windows_capture::{
capture::GraphicsCaptureApiHandler,
encoder::{VideoEncoder, VideoEncoderQuality, VideoEncoderType},
frame::Frame,
graphics_capture_api::InternalCaptureControl,
monitor::Monitor,
settings::{ColorFormat, CursorCaptureSettings, DrawBorderSettings, Settings},
};
// This struct will be used to handle the capture events.
struct Capture {
// The video encoder that will be used to encode the frames.
encoder: Option<VideoEncoder>,
// To measure the time the capture has been running
start: Instant,
}
impl GraphicsCaptureApiHandler for Capture {
// The type of flags used to get the values from the settings.
type Flags = String;
// The type of error that can occur during capture, the error will be returned from `CaptureControl` and `start` functions.
type Error = Box<dyn std::error::Error + Send + Sync>;
// Function that will be called to create the struct. The flags can be passed from settings.
fn new(message: Self::Flags) -> Result<Self, Self::Error> {
println!("Got The Flag: {message}");
let encoder = VideoEncoder::new(
VideoEncoderType::Mp4,
VideoEncoderQuality::HD1080p,
1920,
1080,
"video.mp4",
)?;
Ok(Self {
encoder: Some(encoder),
start: Instant::now(),
})
}
// Called every time a new frame is available.
fn on_frame_arrived(
&mut self,
frame: &mut Frame,
capture_control: InternalCaptureControl,
) -> Result<(), Self::Error> {
print!(
"\rRecording for: {} seconds",
self.start.elapsed().as_secs()
);
io::stdout().flush()?;
// Send the frame to the video encoder
self.encoder.as_mut().unwrap().send_frame(frame)?;
// Note: The frame has other uses too for example you can save a single for to a file like this:
// frame.save_as_image("frame.png", ImageFormat::Png)?;
// Or get the raw data like this so you have full control:
// let data = frame.buffer()?;
// Stop the capture after 6 seconds
if self.start.elapsed().as_secs() >= 6 {
// Finish the encoder and save the video.
self.encoder.take().unwrap().finish()?;
capture_control.stop();
// Because there wasn't any new lines in previous prints
println!();
}
Ok(())
}
// Optional handler called when the capture item (usually a window) closes.
fn on_closed(&mut self) -> Result<(), Self::Error> {
println!("Capture Session Closed");
Ok(())
}
}
pub fn capture_window(_hwnd: HWND) -> Result<(), ()> {
/* let window = Window::from_raw_hwnd(hwnd); */
let primary_monitor = Monitor::primary().unwrap();
let settings = Settings::new(
// Item To Captue
primary_monitor,
// Capture Cursor Settings
CursorCaptureSettings::Default,
// Draw Borders Settings
DrawBorderSettings::Default,
// The desired color format for the captured frame.
ColorFormat::Rgba8,
// Additional flags for the capture settings that will be passed to user defined `new` function.
"Yea This Works".to_string(),
)
.unwrap();
// Starts the capture and takes control of the current thread.
// The errors from handler trait will end up here
Capture::start(settings).expect("Screen Capture Failed");
Ok(())
}
from windows-capture.
Hey, can you check if the start_free_threaded function works or not? also, what is your Windows version?
from windows-capture.
I'm using win11 23h2, and let me see what I found related to start_free_threaded
from windows-capture.
hmmm start_free_threaded isn't called in any part of the code I see, maybe is my editor not matching the reference or maybe a macro? but I don't find where start_free_threaded is called.
from windows-capture.
no I mean't instead of Capture::start use Capture::start_free_threaded.
because I think Tauri initializes the WinRT in the main thread itself so you should run the capture in another thread.
Capture::start_free_threaded returns a handle to the capturing thread which you can use to call the struct or get the thread handle and etc.
from windows-capture.
ohh, let me try this
from windows-capture.
yeap that is, the thread. but now it freeze on send_frame
"2" was never printed and error is not emitted:
self.encoder.as_mut().unwrap().send_frame(frame).expect("Failed to send frame");
println!("\r\n2");
from windows-capture.
Ok... thats weird I have to try to do the same in Tauri
from windows-capture.
Related Issues (20)
- Request help for a conditional capture of a single image HOT 4
- Border HOT 3
- ⭐ Cross-platform Support HOT 1
- [BUG 🪲] When the window is not maximized, the obtained image is incorrect. HOT 3
- Expose Capture::GraphicsCaptureSession::IsSupported() HOT 1
- [BUG 🪲] Python version returns error when trying to start a WindowsCapture HOT 1
- [BUG 🪲] Typo on `CursorCaptuerSettings`? HOT 1
- [BUG 🪲] Graphics Capture Error HOT 4
- [FEATURE ⭐] HOT 1
- [BUG 🪲] HOT 1
- [FEATURE ⭐] is there a way to get list of active tabs and user can select the specific tab to get screen recorder HOT 4
- [BUG 🪲] window capture getting pink color output in the recorded video HOT 9
- [BUG 🪲] Doesn't start recording HOT 1
- [BUG 🪲] Error while installing with pip HOT 5
- [BUG 🪲]Capture does not end in a multi-threaded scenario. HOT 5
- [FEATURE ⭐] Improved guide how to setup library HOT 4
- [BUG 🪲] Capture Session Threw An Exception -> Graphics Capture Error HOT 1
- [FEATURE ⭐] ECAL support HOT 3
- [BUG 🪲] dosent work
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from windows-capture.