{"id":2080,"date":"2016-02-09T18:21:13","date_gmt":"2016-02-09T18:21:13","guid":{"rendered":"http:\/\/emtunc.org\/blog\/?p=2080"},"modified":"2017-02-24T15:06:35","modified_gmt":"2017-02-24T15:06:35","slug":"setting-rtsp-relay-live555-proxy","status":"publish","type":"post","link":"https:\/\/emtunc.org\/blog\/02\/2016\/setting-rtsp-relay-live555-proxy\/","title":{"rendered":"Setting up a RTSP Relay with Live555 Proxy"},"content":{"rendered":"<p>In this brief how-to, I will show you how you can set up a RTSP relay\/proxy server using the <a href=\"http:\/\/www.live555.com\/\" target=\"_blank\">Live555<\/a> Proxy.<\/p>\n<p>Essentially what the Live555 proxy server allows you to do is to connect to a <em>backend<\/em> video feed and relay it to your RTSP clients via unicast. The number of clients you can relay to depends on the hardware of your proxy server as well as the network. Bandwidth usage can easily be calculated by multiplying the backend feed in KB\/s by the number of clients connected to your relay server.<\/p>\n<p><!--more--><\/p>\n<h3>My set-up<\/h3>\n<ul>\n<li>Ubuntu Server 14.04 LTS x64<\/li>\n<li>VLC client running the latest version &#8211; you can also use something like <a href=\"http:\/\/www.live555.com\/openRTSP\/\" target=\"_blank\">OpenRTSP<\/a><\/li>\n<\/ul>\n<h3>Let&#8217;s get started<\/h3>\n<ol>\n<li>First let&#8217;s install the essential components required to compile and build the Live555 proxy.\n<pre class=\"lang:default decode:true\">sudo apt-get install make\r\nsudo apt-get install build-essential<\/pre>\n<\/li>\n<li>Let&#8217;s grab the package and unzip it\n<pre class=\"lang:default decode:true\">wget http:\/\/www.live555.com\/liveMedia\/public\/live555-latest.tar.gz\r\ntar -xzf live555-latest.tar.gz<\/pre>\n<\/li>\n<li>Now\u00a0<strong>cd<\/strong> to the new directory (it should be called\u00a0<strong>live<\/strong>)<\/li>\n<li>Run the following to generate the Makefiles &#8211; this will allow you to use the make command later to compile the source code\n<pre class=\"lang:default decode:true\">.\/genMakefiles linux-64bit<\/pre>\n<p>If you&#8217;re using another dsitro (i.e., not Ubuntu 64bit) then you&#8217;ll need to substitute linux-64bit with something else &#8211; these are the ones that start with\u00a0<strong>config.*<\/strong> where\u00a0<strong>*<\/strong> is your architecture.<\/li>\n<li>Now you may want to take at the look at the source code for the proxy server as not only will it help you understand how it works but you can also make some adjustments to suit your environment.<br \/>\nI made three\u00a0tweaks here for our environment. One was to increase the\u00a0<strong>OutPacketBuffer::maxSize<\/strong> to a larger number (this is the maximum frame size &#8211; our Panosonic HE-130&#8217;s exceeded the default of 100,000 bytes).<br \/>\nThe other was to change the default\u00a0<em>frontend<strong>\u00a0<\/strong><\/em>stream URLs from the default of rtsp:\/\/relay\/<strong>proxyStream-<em>{n}<\/em><\/strong> to a more simple rtsp:\/\/relay\/<strong>stream<em>{n}<\/em><\/strong> where\u00a0<em>n<\/em> is the stream number if &gt; 1 input streams.<br \/>\nThe final adjustment I made was to change the secondary port number from 8554 to 554 (yes this is the same as the primary port). The reason I did this is to prevent user error in case someone forgets to run the proxy server as sudo. In a scenario where someone forgets to run the server as sudo then the proxy server will attempt to open port 8554 which we don&#8217;t want.The source code can be found in the \/live\/proxyServer folder. The file name is\u00a0<strong>live555ProxyServer.cpp<\/strong>. Don&#8217;t forget to make a backup first! (copy live555ProxyServer.cpp live555ProxyServer.cpp.bak)<br \/>\n<strong><br \/>\n<\/strong><\/li>\n<li>Now we can compile the code by running the\u00a0<strong>make<\/strong> command in the \/live directory. This will take a short while to compile but it should succeed without issues.<\/li>\n<li>That&#8217;s it! You&#8217;re ready to relay now.<\/li>\n<\/ol>\n<h3>RTSP relay example<\/h3>\n<p>Imagine a scenario where you have two cameras which can spit out a RTSP feed. The RTSP url is as follows: rtsp:\/\/camera1\/MediaInput\/h264\/stream_1 and\u00a0rtsp:\/\/camera2\/MediaInput\/h264\/stream_1<\/p>\n<p>Now to relay these feeds, simply run the following:<\/p>\n<pre class=\"lang:default decode:true\">sudo .\/live555ProxyServer -v\u00a0rtsp:\/\/camera1\/MediaInput\/h264\/stream_1\u00a0rtsp:\/\/camera2\/MediaInput\/h264\/stream_1<\/pre>\n<p><strong>Note: it is important to run this as sudo otherwise you won&#8217;t be able to open port 554 which is the default for RTSP. You can open a port higher than 1024 but it means your clients will have to enter the port number after the URL which can be ugly (the proxy server will try 8554 by default if it cannot open 554)<\/strong><\/p>\n<p>The output will automatically spit out the RTSP feeds for the relay server. For example you will get something like this: rtsp:\/\/relay-server\/proxyStream-1 and rtsp:\/\/relay-server\/proxyStream-2<\/p>\n<h3>Bonus: Monitor your bandwidth utilisation<\/h3>\n<p>There are many tools out there which you can use to monitor network utilisation but I like <strong>slurm<\/strong>.<\/p>\n<pre class=\"lang:default decode:true  \">sudo apt-get install slurm\r\nsudo slurm -i eth0<\/pre>\n<p>This assumes your NIC is on eth0.<\/p>\n<p>If there is a stream running, you will see that the current RX speed is the bandwidth utilisation of the feed from the relay server to the camera. The TX speed will be the RX speed * number of clients.<\/p>\n<p>I hope this helps someone out there!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this brief how-to, I will show you how you can set up a RTSP relay\/proxy server using the Live555 Proxy. Essentially what the Live555 proxy server allows you to do is to connect to a backend video feed and relay it to your RTSP clients via unicast. The number of clients you can relay [&hellip;]<\/p>\n","protected":false},"author":32,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":""},"categories":[1],"tags":[223,224],"class_list":["post-2080","post","type-post","status-publish","format-standard","hentry","category-tech","tag-live555","tag-rtsp"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1trTO-xy","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/posts\/2080","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/comments?post=2080"}],"version-history":[{"count":11,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/posts\/2080\/revisions"}],"predecessor-version":[{"id":2471,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/posts\/2080\/revisions\/2471"}],"wp:attachment":[{"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/media?parent=2080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/categories?post=2080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/tags?post=2080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}