JMF Solutions

Transmitting Video over RTP

 
Problem
How to transmit video over the network using JMF and JMF-RTP. You may want to transmit video from one computer to another. Or you may want to broadcast a live video feed to your company's intranet. The source of the video can be a file,  live video using a video capture device or any other source supported by JMF.

Solution
The VideoTransmit class is a simple wrapper that can be programmed to take video input from a source of your choice and transmit the video to a destination computer or network in JPEG format. 

The JMF API is used to read the source and convert it to packetized JPEG data. The RTP API implementation included in JMF will then transmit the video using the RTP protocol.

The VideoTransmit class takes three parameters in the constructor - the source locator, the destination IP address and the destination port number.

The source locator can be -
  • a file name such as "file:/C:/media/speech.mov",
  • an http locator such as "http://mediacentral.com/speech.avi",
  • or a capture datasource such as "vfw://0" or "sunvideo://0/1/JPEG"
      vfw: is used on Windows and sunvideo: is used on Solaris. If you have a more recent PCI based Sun Workstation, then use sunvideoplus:. When using vfw, it will pop-up a format dialog when creating the processor. You should select the size of the video that you would like to transmit at.
The IP address should be the IP address of the computer that should receive your transmission. If you want all the computers on your subnet to receive the transmission, then use 255 as the last number in your IP address. For example, "129.130.131.132" can be used for a point to point transmission and "129.130.131.255" can be used for all computers that are on your subnet. Consult your system administrator if you're not sure what these IP addresses mean. You can also refer to the JMF RTP documentation in the JMF Programmer's Guide for more information on RTP transmission and reception.

The Port number can be any port number that is not in use by any other service on your computer. For example, you can use "22222". Make sure that it is an even number. Once again, refer to the Programmer's Guide.

The sample program can be used as a utility class as well as standalone. There is a main method that takes three command line parameters. If all goes well, the video will be sent out for 30 seconds and then the application will exit. This 30 second limit is because there is no GUI that allows you to specify when to stop the transmission. When doing live video capture it is very important to properly terminate the capture and release the device by calling stop and close on the capturing processor.

Note: The source video, whether its a file or live video, needs to be in a format that can be converted to JPEG/RTP. Cinepak, RGB, YUV and JPEG are good formats. Other formats may not work due to restrictions inside the processor. Also the dimensions of the video should be a multiple of 8x8. For example, 320x240, 176x144 are good sizes and 240x180, 90x60 are not. Experiment with different formats to see what works best for you.
 
 
Requirements
 
Platform: JDK 1.1.6 or later
JMF API: 2.0 or later
Implementation: AJ, WPP, SPP *
Hardware: [optional] Video Capture card required for live capture.


* AJ = All Java, WPP = Windows Performance Pack, SPP = Solaris Performance Pack
 
Related Classes
 
 
How to run this sample
 
  1. Download and compile the source file.
  2. Run VideoTransmit with the required 3 command line parameters

  3. For example,

    java VideoTransmit vfw://0 129.144.251.182 42050
     
  4. Or write your own little program that uses the VideoTransmit class to create, start and stop an RTP transmit session.
  5. To receive the transmission on the client side, run JMStudio as follows:

    java JMStudio rtp://<sourceIP>:<port>/video

    Where <sourceIP> is the IP address of the transmitting computer and the port number is the same one that is used on the transmitting side.
 
Source Code
 
 
See Also
 
  • JMF 2.0 Programmer's Guide
Left Curve
Java SDKs and Tools
Right Curve
Left Curve
Java Resources
Right Curve


Duke's Choice RHS Banner

JavaOne 2014 Replay banner