Friday, March 11, 2011

RTSP - Real Time Streaming Protocol (RTSP)

RFC 2326 define the specification for RTSP, Real Time Streaming Protocol.

RTSP is mainly use for setting up streaming and control for audio and video media. As an overview, RTSP will be used with RTP over UDP or TCP. In this entry, I will describe the how to use RTSP as media setup command

The common commands for RTSP is OPTION, DESCRIBE, SETUP, PLAY, TEARDOWN.

The above commands set is enough to connect or disconnect from a media stream. I will briefly describe each commands


OPTION command is used by client to ask server what type of commands does it support. The request and response example is


DESCRIBE is used by client to ask server to provide media stream information for a certain media URL Commonly, the DESCRIBE command provide the SDP, Session Description Protocol, for the given media URL. The request and response example is


SETUP is used by client to setup necessary port, track, etc for a given media stream. It is used to tell the server what type of transport, UDP or TCP, should be used for the media streaming. The request and response example is


PLAY command is used by the client to tell server to start providing the media stream bytes via the setup channel. The request and response example is


TEARDOWN command is used by client to tell server that the current media stream to be stop. All resource related to this stream can be removed. The request and response example is

The General flow for the commands is

To setup and play a stream


To Terminate


As a complete example, the flow of command for client and server to setup and play a unicast media stream is

Below is a screenshot of RTSP commands in action

JAVA - Create RTSP Connection

Using Java to create RTSP connection is simple. Below is an example for sending a OPTION command

Socket s = new Socket();
s.connect("rtsp://your.url:554/track.sdp", 60000);
s.connect(address, timeout);
PrintStream out = new PrintStream(s.getOutputStream());
StringBuffer b = new StringBuffer();
b.append("OPTIONS * RTSP/1.0 \r\n");
b.append("CSeq: 1\r\n");
b.append("User-Agent: MyClient \r\n");
b.append("Connection: Keep-Alive \r\n");

Above provide a skeleton code for using JAVA to create a RTSP OPTION command. As you can see, all you need to do is to the follow

1. Create a JAVA socket
2. Use the socket output stream to send the commands. Simple follow the respective command as state in the above section.
3. After sending, read in the response from socket input stream socket (s.getInputStream())and parse it respectiviely.

NOTE: If you have notice, at the end of the command, I provided an extra


This is needed to tell RTSP server that the command is ended. It is a common mistake when trying to communicate with a RTSP server.

For more details you can find in


  1. Thanks. Important commands nicely explained.

  2. I am glad that my notes helps :)

  3. hey
    I want to create a program in VC++/C++ using sockets to receive streaming data from live media server.
    can u give me a clue or pseudo code for that????

  4. First, you need to know Socket Programming on C++.

    This site should help you.

    Base on the socket tutorial, you need to create a socket that specify RTSP connector. Get the socket output stream, write OPTION to the media server. The server should reply a RTSP response to you with status 200.

    RTSP is a simple protocol that is based on plain text. So, all you need is to perform text parsing on socket stream, request and response base on the RFC and you should be good to go.


Facebook - Control privacy setting of liked page

By default, Facebook displayed your liked page to public. It is the user responsibility to adjust the privacy setting. And in my opinion, F...