JMF Solutions

Screen Grabber [DataSource]

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:


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


Note: This program requires JDK 1.3 or higher to compile and to run.
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
  1. Compile the DataSource and LiveStream classes:
    javac -d .
  2. Run using JMStudio:
    java JMStudio screen://0,0,160,120/10
Source Code
See Also
Left Curve
Java SDKs and Tools
Right Curve
Left Curve
Java Resources
Right Curve
Duke's Choice Awards Nomination RHS

VTS OnDemand RHS Banner

Virtual Tech Summit Sept 2015 RHS banner

JavaOne 2014 Replay banner