views:

675

answers:

3

I wanted to find out how can one capture screencast using java. I know that using Robot class one can get a screenshot but how do I go about capturing it as a video and then uploading it to the server? How exactly would that work?

ideas?

+2  A: 

With a pure Java solution, I doubt that it will work, but it depends of course on what your interpretation of "video".

On my desktop with a 1920x1200 resolution, I am able to get about 20 frames per second when using the Java Robot to capture the entire screen. Since each image contains >6 MByte of uncompressed data, I would need more than 1 Gbps bandwidth to transmit the raw data of these images to a server. Most probably, requiring so much bandwidth is not acceptable, so you either have to decrease the number of frames per second or apply some kind of compression to the images.

One possibility is to compress each image using one of the image formats supported by ImageIO. The size of the compressed images will of course depend heavily on what is actually shown on the screen, but the performance of the compressors is not particularly good. Compressing to PNG ought to give the best lossless compression ratio for most desktop content, but at least my computer is only able to process just about 2 frames per second. Using the JPEG compressor with default quality settings reaches about 5 frames per second.

Using common video codecs through an abstraction layer like jffmpeg will probably achieve both better performance and better compression ratio, but I doubt that mainstream video codecs like WMV or H.264 are suitable for common desktop content.

If you really require a pure Java solution (and are not able to use any of the available standalone software, which do what you're asking for), I would make an attempt to implement my own, simple compression algorithm. With common desktop activity, there ought to be very little difference between most consecutive screen shots, so what might work quite well is to transmit the first frame completely and after that implement an algorithm to roughly detect rectangles, in which changes have been made and then transmit only these combined with JPG or preferrably (quality) PNG compression.

jarnbjo
How does screencast-o-matic.com do it with such a nice frame rate? I understand and agree with you that a very good compression algorithm will be needed.
John Stewart
How should I know? First of all, they only capture a small part of the screen (640x480?) and a part of the applet is implemented in native code. Perhaps you manage to debug through the decompiled applet code if you really want to know.
jarnbjo
+1 Nice try to explain. Thanks.
Favonius
A: 

Or use Xuggler, a better wrapper for FFmpeg in Java. In fact, the code for capturing the screen and encoding the video is one of the standard tutorials.

Xuggle
Xuggler doesn't let me run the lib as an applet. (or am i missing something?)
John Stewart
That's right; today it doesn't support applets, but it's on our roadmap for the future.
Xuggle
+1  A: 

I'm also curious about this. https://www.screencast.com/ is currently doing just this with a pure java (or at least straight out of the browser) experience.

alex