15

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?

Obaid
  • 4,328
  • 9
  • 42
  • 42

5 Answers5

14

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
  • 33,923
  • 7
  • 70
  • 94
  • 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. – Obaid Jan 13 '10 at 20:04
  • 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 Jan 13 '10 at 21:33
  • The meat of SOM is a standalone Java app, not an applet. Looks like it uses a compiled version of ffMPEG to do the compression/editing, but all the files are stored locally until the completed screencast is uploaded through the app. – alalonde Feb 28 '12 at 19:49
5

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.

Art Clarke
  • 2,495
  • 18
  • 15
2

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
  • 2,036
  • 2
  • 16
  • 19
2

You can just use something like Java to a native FFMPEG build, and execute the command line at runtime. Here is an applet that I made that does just that: http://have2chat.net/screencast/

David
  • 21
  • 1
  • If it is possible, for learning purpose can you please share the source code for it? It would be really great if you can show on how you could access the webcam from applet – Jatin Sep 03 '13 at 08:44
1

I have downloaded the main capture *.JAR file for the Screencast-O-Matic.com. To download the file:

  1. Go to http://screencast-o-matic.com/jars/ScreencastOMaticRun-1.0.5.jar
  2. Save the file
  3. Extract the contents (I DO NOT intend to use this commercially!)