Video Transmit Using JMF

Here is One example for video transmit using JMF:

import java.awt.*;

public class VideoTransmit {

private MediaLocator locator;
private static MediaLocator ml;
private String ipAddress;
private String port;
private Processor processor = null;
private DataSink rtptransmitter = null;
private DataSource dataOutput = null;
public static CaptureDeviceInfo di = null;

public VideoTransmit(MediaLocator locator,
String ipAddress,
String port) {

this.locator = locator;
this.ipAddress = ipAddress;
this.port = port;

public synchronized String start() {
String result;
result = createProcessor();
if (result != null)
return result;

result = createTransmitter();
if (result != null) {
processor = null;
return result;


return null;

public void stop() {
synchronized (this) {
if (processor != null) {
processor = null;
rtptransmitter = null;

private String createProcessor() {
if (locator == null)
return "Locator is null";

DataSource ds;
DataSource clone;

try {
ds = Manager.createDataSource(locator);
} catch (Exception e) {
return "Couldn't create DataSource";

try {
processor = Manager.createProcessor(ds);
} catch (NoProcessorException npe) {
return "Couldn't create processor";
} catch (IOException ioe) {
return "IOException creating processor";

boolean result = waitForState(processor, Processor.Configured);
if (result == false)
return "Couldn't configure processor";

TrackControl [] tracks = processor.getTrackControls();

if (tracks == null || tracks.length < 1) return "Couldn't find tracks in processor"; boolean programmed = false;
for (int i = 0; i < tracks.length; i++) {
Format format = tracks[i].getFormat();
if ( tracks[i].isEnabled() && format instanceof VideoFormat && !programmed) { Dimension size = ((VideoFormat)format).getSize();
float frameRate = ((VideoFormat)format).getFrameRate();
int w = (size.width % 8 == 0 ? size.width : (int)(size.width / 8) * 8);
int h = (size.height % 8 == 0 ? size.height : (int)(size.height / 8) * 8);
VideoFormat jpegFormat = new VideoFormat(VideoFormat.JPEG_RTP, new Dimension(w, h), Format.NOT_SPECIFIED, Format.byteArray, frameRate);
tracks[i].setFormat(jpegFormat); System.err.println("Video transmitted as:"); System.err.println(" " + jpegFormat); programmed = true; } else tracks[i].setEnabled(false); } if (!programmed) return "Couldn't find video track";
ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
processor.setContentDescriptor(cd); result = waitForState(processor, Controller.Realized); if (result == false) return "Couldn't realize processor";
setJPEGQuality(processor, 0.5f); dataOutput = processor.getDataOutput(); return null; } private String createTransmitter() { // rtp:// String rtpURL = "rtp://" + ipAddress + ":" + port + "/video"; MediaLocator outputLocator = new MediaLocator(rtpURL); try { rtptransmitter = Manager.createDataSink(dataOutput, outputLocator);;
rtptransmitter.start(); dataOutput.start(); } catch (MediaException me) { return "Couldn't create RTP data sink"; } catch (IOException ioe) { return "Couldn't create RTP data sink"; } return null; } void setJPEGQuality(Player p, float val) { Control cs[] = p.getControls(); QualityControl qc = null; VideoFormat jpegFmt = new VideoFormat(VideoFormat.JPEG); for (int i = 0; i < owner =" ((Owned)cs[i]).getOwner();" j =" 0;" qc =" (QualityControl)cs[i];" statelock =" new" failed =" false;" failed =" true;" failed =" false;" state ="="" state ="=""> ");
ml = args[0];
String url1 = args[1];
String port1 = args[2];
VideoTransmit vt = new VideoTransmit(ml, url1, port1);

String result = vt.start();
if (result != null) {
System.err.println("Error : " + result);

System.err.println("Start transmission for 60 seconds...");

try {
} catch (InterruptedException ie) {


System.err.println("...transmission ended.");



For run: java media_location IPaddress Port
JMF download: SUN

Hardware Requirements

* 166 MHz Pentium, 160 MHz PowerPC, or 166 MHz UltraSparc
* 32 MB RAM or greater
* Optional: An appropriate sound card for audio play back, if necessary. For example, a SoundBlaster-compatible card for Windows machines without built-in audio support, or an Ultimedia sound card for AIX machines without built-in audio support.

Installation Instructions

1. Download the version of JMF you want to install by selecting a download format and and clicking the continue button.

The downloaded file is an executable. For Windows, it's an InstallShield executable; for Solaris, it's a self-extracting shell script; otherwise it's a generic zip file.

2. If you are installing the JMF Performance Pack for Windows

* Run the executable by double-clicking on the

NOTE: The Windows installation program automatically detects whether or not Netscape Communicator 4.03 or later is installed and then installs JMF for its use! If you are using Netscape Communicator 4.04 or 4.05, then you must install the JDK 1.1 patch for Netscape Communicator before you can run any JMF applets. Netscape Communicator 4.06 or greater already supports JDK 1.1 without the patch.

If you are installing the JMF Performance Pack for Solaris SPARC

* Change directories to the install location.
* Run the command % /bin/sh ./jmf-2_1_1e-solaris-sparc.bin

If you are installing the JMF Performance Pack for Linux

* Change directories to the install location.
* Run the command % /bin/sh ./jmf-2_1_1e-linux-i586.bin

If you are installing a zip file

* Run the appropriate zip command for your system, e.g. winzip or unzip to extract JMF onto your system.

3. IMPORTANT: You must finish setting up JMF by following the setup instructions included in the JMF Implementation Documentation. You can download the documentation package separately or view it online. ----->


Francisco said…
hello you!
I downloaded your code and it's very interesting but I have a Problem, I can't compile the file because this method can't be found: boolean result = waitForState(processor, Processor.Configured);

Thank's a lot.
Anonymous said…
Could you tell me how to transmit a video to a website from your machine (online streaming)
Abinash said…
I am constantly facing the folowing exception: Could not connect to capture device Error instantiating class:
ocol.vfw.DataSource : Could not connect to capture device
at VideoTransmit.createProcessor(
at VideoTransmit.start(
at VideoTransmit.main(
Exception in thread "main" java.lang.NullPointerException
at VideoTransmit.waitForState(
at VideoTransmit.createProcessor(
at VideoTransmit.start(
at VideoTransmit.main(

Can you please tell me what i need to do?

Popular posts from this blog

Secure Spring Boot REST API using Basic Authentication

Integrating Swagger with Spring Boot REST API

Building a RESTFul Service using Spring Boot