robmikh / displayrecorder

A utility to record displays.
MIT License
16 stars 7 forks source link

Is there a way to record only the particular window screen with specified resoultion #13

Closed yashwanth2804 closed 5 months ago

yashwanth2804 commented 5 months ago

Is it possible to record only the given window in the screen and save with the window's resoultion or predefiened resoultion provided while saving

robmikh commented 5 months ago

It's certainly possible, it's just not implemented here. At a minimum, you would need to create a GraphicsCaptureItem for the window you'd like to record and use that instead of the item we create for the display. If you have the HWND of the window you'd like to record, just call the other method on the IGraphicsCaptureItemInterop interface to create the item.

The rest of the pipeline should more or less work without modification. The one complication is that if you use the size of the window as the output resolution, you may run into issues where the encoder doesn't like that size.

I have other projects that have implemented this type of recording, namely CaptureVideoSample and SimpleRecorder. If you'd like to see more on how to create a capture item for a window in Rust, you can checkout screenshot-rs.

I'm going to close this issue, but feel free to ask questions.

yashwanth2804 commented 5 months ago

Thank you for the reply , I did managed to achive it

 let window_foreground = unsafe { GetForegroundWindow() };
    let item = create_capture_item_for_window(window_foreground .as_raw_hwnd())?;

pub fn create_capture_item_for_window(display_hwnd: HWND) -> Result<GraphicsCaptureItem> {
    let interop = windows::core::factory::<GraphicsCaptureItem, IGraphicsCaptureItemInterop>()?;
    unsafe { interop.CreateForWindow(display_hwnd) }
}