russelltg / wl-screenrec

High performance wlroots screen recording, featuring hardware encoding
Apache License 2.0
266 stars 10 forks source link

Make it a library #61

Closed axelkar closed 4 months ago

axelkar commented 4 months ago

I'd really like to use it as a library in a project I'm working on. XCap doesn't seem like it's good for streams and I can't find any other recently updated Rust libraries, which work for any kind of Wayland. I can try making a nice documentated API for you to publish onto crates.io.

russelltg commented 4 months ago

Which part exactly do you want as a library? This tool is pretty much just glue between wayland-protocols[-wlr], ffmpeg-next crates.

axelkar commented 4 months ago

I'd be happy with shared glue code, especially if it gets support for GNOME and KDE.

russelltg commented 4 months ago

So the API would take in a region spec and output....what? Encoded video?

axelkar commented 4 months ago

So the API would take in a region spec and output....what? Encoded video?

What do you mean by region spec? Regarding the output, I'll be using raw RGBA frames for my project but it could be configurable.

russelltg commented 4 months ago

I see. Region spec being what part of the screen to capture.

The primary reason that wl-screenrec is efficient is it never actually touches the raw textures, it uses dmabuf to just pass around handles to GPU memory.

If you want CPU surfaces then there is little overlap in what wl-screenrec does and what you want it seems?

axelkar commented 4 months ago

.. pass around handles to GPU memory.

I'll be using the GPU for rendering, is there an easy way to get Vulkan or wgpu texture handles for frames?

russelltg commented 4 months ago

For sure, but that decreases overlap with this project even more.

To get it into wgpu/vulkan memory, all you have to do is allocate a surface with the right format (the Linux dmabuf Wayland protocol gives you the format), then export it as an EGLImage, get the fd, then pass it to the the screencopy protocol.

Happy to help you out with this, altho don't think there is any code we can share ....

russelltg commented 4 months ago

Going to go ahead and close the issue--best of luck and I hope this is at least useful example code!

axelkar commented 2 months ago

Libwayshot looks great but doesn't seem to implement anything related to DMA-BUF.

I guess wgpu is a blocker too for doing direct GPU texture passing: https://github.com/gfx-rs/wgpu/issues/2320

Could I manually do Vulkan magic with say ash or vulkano to get the DMA-BUF imported and use this? https://github.com/gfx-rs/wgpu/pull/3355

Thanks!

russelltg commented 2 months ago

Yes, you should be able to to manually do this per-wgpu backend you want to support