Find the answer to your Linux question:
Results 1 to 10 of 10
I'm using an RTSP server on Linux that opens a pair of ports each time there's a connection request. The problem is that it dynamically chooses that those ports over ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2014
    Posts
    5

    How can I map multiple ports into one ?


    I'm using an RTSP server on Linux that opens a pair of ports each time there's a connection request. The problem is that it dynamically chooses that those ports over a wide range of port numbers, making a different choice each time, and does not have the ability to control the choice of port numbers. Unless I have only one of these RTSP servers and put it in a DMZ in my router, it's impossible to access it from the Internet.

    How can I configure iptables or something that runs on the Linux machine that hosts the RTSP server and translates a wide range of internal port numbers to a SINGLE externally accessible port number ?

    Thanks in advance for your help.

  2. #2
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    1,660
    You should be able to restrict the range being chosen but no, you can't merge multiple ports into one.

    Strictly speaking it isn't the RTSP protocol that is using the ports though it sets them up. The actual behaviour depends on the type of stream being setup. A common scenario sees the server launch two sockets after receiving a RTSP request, one for RTP and one for RTCP. The server informs the client that it should connect to these ports. The range of these ports therefore influences the number of clients supported.

    Irrespective of that; connections are uniquely identified by port and address and multiplexing would only be an option for one client and then only if the protocol supported it. I mention that only because there has been the suggestion that it could.

  3. #3
    Just Joined!
    Join Date
    May 2014
    Posts
    5
    Thank you for your reply but I'm missing something... IP cameras have a URL of the form rtsp://<ipaddress>:554. They handle all communications over that single port, with multiple clients, via the Internet, without having to be placed in a DMZ so multiple ports can be assigned by RTSP and accessed by the clients. tcp is used for control and udp is used for video. Why can't a Linux-based RTSP server do the same ?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    1,660
    554 is the standard RTSP port and RTSP itself only uses one port. RTSP sets up the ports used by the application. What happens after that depends on the actual application. Saying they handle all communication over a single port is incorrect however they may only have that port configured. The other ports are set up by the server on demand depending on the application being used. RTSP is a control protocol, it doesn't actual stream data - despite the misleading name.

  6. #5
    Just Joined!
    Join Date
    May 2014
    Posts
    5
    Thank you for your reply. Let's focus on the networking issues of IP cameras since that's the root of the port problem.

    It is common for IP cameras to receive a RTSP request on port 554 via tcp for live video. It is also common for the resulting video to also be accessed via port 554, using UDP. Are you saying that (1) a RTSP request to such as camera causes the RTSP server to communicate with a video application within the camera, and the application, not the RTSP server, chooses to always provide live video via UDP on port 554, even when there are multiple clients, and (2) that other systems may also receive a RTSP request on port 554 via tcp for media, BUT that the application instructs the RTSP server to open two ports, not just one, and to select different pairs of ports for each request ? If so, it seems I need to focus on the application within the camera providing the media and communicating with the RTSP server, and possibly on the client requesting the media, not the RTSP server. Do you agree ? It is the opening of multiple ports, on different port numbers, that I thought was the fault of the RTSP server and that I was trying to defeat by mapping many ports into one.

  7. #6
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    1,660
    These protocols are used by applications in different ways. To understand what is happening you need to know the protocols being used and how they're being used.

    1) Not likely. They most likely are part of one application. RTSP is a protocol not an application. An RTSP server communicate using the protocol. If the camera is to send data to a server it will need to know what server to send it. However it is usually a client and not a server that wants the data so the application providing the UDP stream would ask the client, via the RTSP protocol to connect to the UDP server, on port 554 in your example (note that UDP 554 and TCP 554 are two separate sockets).

    2) Yes.Again,RTSP is a protocol. It can and is used for many applications. Often it is used in conjunction with RTP which uses another protocol RTCP which each require there own port.

    Find out what ports are required to be open by the server you wish to run then restrict it to the minimum required. There is no multiplexing of ports in this though.

    When an application is a server it opens what is called a server socket. Unlike client sockets there can only be one of these per network interface. If a server application opens a server socket on TCP port 554, no other application can open that port as a server. The same is true of a UDP server. Linux provides a programmer with a number of means to accept multiple connections on one server port but multiple applications can't open that same port. What some applications do, and this may be true of the server you're wanting to run, is spawn private server sockets - they will be used by only one client, or at least they won't be used by them all - there may be some internal multiplexing occurring - just not as much.

    So, again, it is a configuration issue for the server you want to run and that will be application specific.

  8. #7
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    1,660
    By the way, what is the RTSP server you're running?

  9. #8
    Just Joined!
    Join Date
    May 2014
    Posts
    5
    It's a media server that's poorly documented for the part I care about. It's VLC, which, when run from the Linux command line, is called cvlc. It receives a H.264 live video stream and makes it accessible using RTSP.

    It is run like this (all one line):

    raspivid -o - -t 0 -w 640 -h 480 -p 0,0,640,480 -b 0 -fps 10 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554}' :demux=h264

    Every time I try to connect on port 8554 using tcp, two udp ports (N and N+1) are opened, and they are randomly chosen over a wide range of port numbers, so I can't access them from the Internet because I can't map them through my router.

  10. #9
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    1,660
    Nice commandline

    Looking at this https://wiki.videolan.org/VLC_command-line_help/ I see
    Code:
    --sout-rtp-port=<integer [-2147483648 .. 2147483647]>
                                     Port
              This allows you to specify the base port for the RTP streaming.
          --sout-rtp-port-audio=<integer [-2147483648 .. 2147483647]>
                                     Audio port
              This allows you to specify the default audio port for the RTP
              streaming.
          --sout-rtp-port-video=<integer [-2147483648 .. 2147483647]>
                                     Video port
              This allows you to specify the default video port for the RTP
              streaming.
          --sout-rtp-ttl=<integer [-2147483648 .. 2147483647]>
                                     Hop limit (TTL)
    and this
    Code:
    --sout-rtp-rtcp-mux, --no-sout-rtp-rtcp-mux
                                     RTP/RTCP multiplexing (default disabled)
    and this

    Code:
    --rtcp-port=<integer [0 .. 65535]>
                                     RTCP (local) port
              RTCP packets will be received on this transport protocol port. If
              zero, multiplexed RTP/RTCP is used.
    and enough other parameters to make your head spin!

    but ... what it looks like to me is you can specify your port settings on the command line. The Muxing bit refers to a proposed specification for using one UDP port (doesn't apply to TCP as I recall) to carry the RTP and RTCP. Other of the params appear to allow you to choose an RTP port and RTCP port.

    Could be what you're looking for.

  11. #10
    Just Joined!
    Join Date
    May 2014
    Posts
    5
    Thank you again for your input. Unfortunately, I still can't get it to work and I can't get any help from the cvlc folks.

    I tried this command to see if I could control the ports:

    Code:
    raspivid -o - -t 0 -w 640 -h 480 -p 0,0,640,480 -b 0 -fps 5 | cvlc -vvv stream:///dev/stdin --noaudio --sout '#rtp{sdp=rtsp://:8554}' --sout-rtp-port=8555 --sout-rtp-port-video=8556 --sout-rtp-port-audio=0 --sout-rtp-rtcp-mux --rtcp-port=8557 --h264-fps=5.0 :demux=h264
    I also tried a simpler version:

    Code:
    raspivid -o - -t 0 -w 640 -h 480 -p 0,0,640,480 -b 0 -fps 5 | cvlc -vvv stream:///dev/stdin --noaudio --sout '#rtp{sdp=rtsp://:8554}' --sout-rtp-port=8555 --h264-fps=5.0 :demux=h264
    But no luck. In both cases, I run 'netstat -nap' to see which ports are assigned by cvlc when a media request from VLC Media Player is made, and cvlc ignores my port specification except for 8554, and dynamically chooses and assigns pairs of ports in the range 30,000 to 60,000.

    All I really need is a RTTP server that can make my H264 video stream available, using port n554 tcp for rttp control, and port n554 udp for rtp video, just like an IP-camera.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •