NiiightmareXD / windows-capture

Fastest Windows Screen Capture Library For Rust And Python 🔥
MIT License
219 stars 32 forks source link

[BUG 🪲] Unable to save frame as an image #93

Open WallyOxen opened 1 day ago

WallyOxen commented 1 day ago

Describe the bug 🐛 I'm not sure if your library is to blame or some wonkiness with the Windows crates/ my version of Windows. I was following the example in the README, added windows-capture v1.4.0 to my project and copied the example into my main.rs file. It runs as expected and saves a 6 second clip. If I uncomment the line frame.save_as_image("frame.png", ImageFormat::Png)?; and import the required Type. I get an error: Screen Capture Failed: FrameHandlerError(WindowsError(Error { code: HRESULT(0x80070057), message: "The parameter is incorrect." }))

I tried to dig into it a bit, but I'm fairly new to Rust and don't understand Windows APIs much at all. It seems to be coming from the frame.buffer function during the texture_desc declaration. I was able to get past the error then if I hard coded the Format from DXGI_FORMAT(self.color_format as u32) to just be DXGI_FORMAT(28) (Rgba8 default). I also was able to change the underlying DXGI_FORMAT struct to handle i32 instead of u32 and changed all of the formats to align as well and that also resolved this issue.

However, even after I hardcode that value it makes it to the self.context.Map function to "Map the texture to enable CPU access" with the same error as above and seems to be something with the D3D11_MAPPED_SUBRESOURCE::default(), but that's where it gets into the Windows API and I'm really not sure of anything there. So this also makes me think it might not be an issue with your crate.

Expected behavior 📝 I expect to get an image saved and overwritten with each frame that's captured during the 6 second recording

OS 🤖

BenedictWilkins commented 18 hours ago

Also facing this issue...

EDIT: it seems like a breaking change was made since commit: 24fae7d24c2ec2d31d63b127a0aa3cfa4261187a If you use this commit directly it should work, in your Cargo.toml:

windows-capture = { git = "https://github.com/NiiightmareXD/windows-capture", rev = "24fae7d24c2ec2d31d63b127a0aa3cfa4261187a"}

WallyOxen commented 16 hours ago

@BenedictWilkins Out of curiosity what version and build of windows are you using?

BenedictWilkins commented 13 hours ago

@WallyOxen OS Name Microsoft Windows 11 Home Version 10.0.22631 Build 22631

did reverting to that commit not work for you?

WallyOxen commented 13 hours ago

@BenedictWilkins I was just now able to test it out. After messing with the missing capture::Context I was indeed able to get it to output screenshots

WallyOxen commented 12 hours ago

It seems that this commit changed frame.rs:205 and removed the D3D11_CPU_ACCESS_WRITE.0 as u32 flag. If I add that back in things work as well