How to capture the contents of the screen and feed it to a JMF player or Processor for purposes such as saving screen shots to disk or transmitting live using RTP.
Java 2 v.1.3 introduced a new class, java.awt.Robot, that provides screen capture facilities. Since this is similar to capturing video from a VCR or camera, it is best encapsulated in a JMF DataSource object. This example shows how to use Robot to create a screen capture DataSource.
The DataSource is a PushDataSource that pushes captured screen shots at regular intervals to the connected Player or Processor. It creates a new protocol "screen" with the following URL syntax:
screen://x,y,width,height/fps
where x, y specify a screen location and width,height specify the size. fps specifies the number of frames to push per second. This can be any fraction greater than zero, although realistic values would be between 0.1 and 30.0.
For example, to capture screen activity in the center of a 1024x768 screen, use
screen://352,264,320,240/5
Note: This program requires JDK 1.3 or higher to compile and to run.
Requirements
| Platform: | JDK 1.3 or later |
| JMF API: | 2.0 or later |
| Implementation: | AJ, WPP, SPP * |
* AJ = All Java, WPP = Windows Performance Pack, SPP = Solaris Performance Pack
Related Classes
How to run this sample
javac -d . DataSource.java LiveStream.java
java JMStudio screen://0,0,160,120/10
Source Code