• Uncategorized

About python : Forward-RTSP-stream-to-remote-socket-RTSP-Proxy

Question Detail

My Apologies for the generality of the question. I have tried many things but nothing seems to work.
I have a server? (let’s call it Server A) that resides in a local area network where there is also an IP-Webcam. That webcam is constantly providing an RTSP feed on the address… let’s say… rtsp:// The camera doesn’t have access to the outside world (it must stay in the LAN, and therefore, only has access to server A, no to server B), but server A does. Sadly, Server A doesn’t have a public IP, so I can not reach into Server A from anywhere in the world. Server A can go out if it wants but no one can get into Server A… (it’s an spoiled brat… too many toys when it was a kid)

Now, there’s another server (server B, to be original) in the aforementioned outside world which is a regular web server with its public IP and all. That server allows people to reach into it (not spoiled, very nice… sets the table, does the dishes… that kind of stuff). Both Server A and Server B are my computers and are running Ubuntu 12.04 and some Python applications I designed (Server B is actually running Django, but I don’t think that’s too relevant). What I mean by this is that I have control over what’s going on in both servers. I can install/uninstall packages, I can open ports, close ports… whatever is needed (I can even format them if I want, although I don’t think that would help much… or yes… who knows?)

                               _____________                                    _____________
    -----------                |           |                                    |           |   
 __ |         |                |           |                                    |           |     
|  \| WebCam  |================| Server A  |===========|  INTERNET  |===========| Server B  |
|__/|         | ->/cam.sdp  <--|           |----------------- > --------------> *           | 
    |         |                |___________|                                    |___________|

The question is: How can I grab the RTSP stream with server A dump it onto a designated socket of server B and open it (with a program able to understand RTSP feeds, such as VLC)?

I’m guessing I need something like an RTSP proxy, maybe? But I don’t really know where to start.

Any hint, link… would be appreciated.

Thank you in advance

Question Answer

I don’t know RTSP, but it seems to be a standard TCP-only protocol. Try to run on server A:

ssh -g -R 554: server_B_hostname

This will open the public port 554 on Server B, and forward it to from A’s point of view.

Some servers have sshd configured to refuse the ssh -g -R forwarding (for no good reason). If you can, you should check /etc/ssh/sshd_config on Server B and add AllowTcpForwarding yes.

RTSP is a controlling protocol which usually runs on port 554 , but videostreams are port negotiated using SDP, meaning that on handshaking the port for RTP transport (UDP)will be decided and for each transport, port number varies. So perhaps you need to forward a range of ports or fix the transport port to a fixed value.

Check out


This will enable you to set up your spoiled brat server to grab the ipcam rtsp stream and push it to server B.

You will need to be able to run this thing on server A, and preferably on serverB too to receive the published stream from serverA. You can use encryption, tls etc…

RTSP is a TCP controlling protocol towards a streaming server. The protocol uses OPTION commands to get info about the stream. When the client has enough info about the server and it’s capabilities can send a PLAY command with a ‘transport string’ telling it. How to stream, Usually on UDP port 554. The client prior to send the PLAY, should be prepared to do recfrom(SRV UDP, PORT). There are transport commands that can make the server to stream on the TCP as well.
Saying this I guess you can write your own RTSP+DATA proxy on the local NET. Keep in mind you have to pass also all the TCP headers going on all the time between parties, telling the client current frames, and such. On the ‘CLOUD’ server you need another custom software to be able to get what you send and expose itself as a rtsp source.

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.