Is it possible to create a screenshot with JOCL?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Is it possible to create a screenshot with JOCL?

sblantipodi
As title.
I need to capture 30 frames per second at 4K resolution.

AWT Robot class is not enough for this purpose, is it possible to use JOCL for this purpose?
Is there an API I can use to capture the screen?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to create a screenshot with JOCL?

gouessej
Administrator
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to create a screenshot with JOCL?

sblantipodi
This post was updated on .
I really, really, appreciate the fast answer, thanks!  
 
But does this works on a specific window only or can I capture everything I have on the screen?  

I'll try to give you a bit of context.

I have created a PC Ambilight project.

This project basically capture the screen image, and sends an encoded version of the "screen colors" to a microcontroller that display that colors to a led strip.

This are the project involved for the purpose
https://github.com/sblantipodi/pc_ambilight
https://github.com/sblantipodi/JavaFastScreenCapture

and this the result:
https://www.youtube.com/watch?v=68pnR5HMCTU

As you can see I use the AWT Robot Java class to capture the screen, it works well and with the right numbers of threads it works even fast.
The problem is that the robot class creates "some stutter" on slow CPUs and it's really CPU intensive if pushed that hard with threads.

Is there a way to get a simple screenshot using JOCL and the GPU and put that screenshot in a BufferedImage?
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to create a screenshot with JOCL?

gouessej
Administrator
You can use com.jogamp.opengl.util.awt.AWTGLReadBufferUtil.readPixelsToBufferedImage​() to do that with JOGL. It's a first step, I think that you could optimize this solution in order to avoid creating a brand new BufferedImage for each frame, look at the source code of GLJPanel to understand how to achieve that. Ideally, you should only modify the internal buffer of an image or (if possible) rather use a canvas.

It's not the right place to ask for help about the third party API you mentioned in your very last sentence which isn't part of JogAmp. I assume that you did a spelling mistake.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to create a screenshot with JOCL?

sblantipodi
thank you for the kind answer, it was a spelling mistake and I corrected it :)
do you know if the readPixelsToBufferedImage() uses the Windows API to capture the screen or if it uses the Desktop Duplication API?

I need to capture 30 frames per seconds and the old Windows API isn't able to bring that kind of performance.

thanks
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to create a screenshot with JOCL?

gouessej
Administrator
readPixelsToBufferedImage() uses the OpenGL API. Maybe it's not what you're looking for.

Have you ever tested VLCJ? This example should help you:
https://github.com/caprica/vlcj/commit/fe8a278872003dab6b903bb8546caea676eabd6d
https://github.com/caprica/vlcj-natives/blob/master/src/main/java/uk/co/caprica/vlcj/binding/LibVlc.java#L1809

I don't see many options to do what you want in Java, maybe have a look at a Gstreamer Java binding if the solution above doesn't work.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to create a screenshot with JOCL?

sblantipodi
OpenGL can't help me because I can't capture all the apps with that.
I really appreciate your kind answer, thanks, and congrats for the good project.