{"id":1909,"date":"2022-08-10T00:03:40","date_gmt":"2022-08-09T22:03:40","guid":{"rendered":"https:\/\/blog.zitnik.si\/?p=1909"},"modified":"2022-08-10T00:03:41","modified_gmt":"2022-08-09T22:03:41","slug":"motion-eye-remote-ssl-rtsp-camera-support","status":"publish","type":"post","link":"https:\/\/blog.zitnik.si\/?p=1909","title":{"rendered":"Motion EYE: Remote SSL + RTSP camera support"},"content":{"rendered":"\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/motioneye-project\/motioneye\/wiki\/Install-On-Raspbian\" target=\"_blank\">Motion EYE project<\/a> does not support cameras providing RTSP streams only. I had one such camera and wanted to add it along other cameras to my Motion EYE system running on a RPi.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/blog.zitnik.si\/wp-content\/uploads\/2022\/08\/add-network-camera.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.zitnik.si\/wp-content\/uploads\/2022\/08\/add-network-camera.jpg\" alt=\"\" class=\"wp-image-1911\" width=\"416\" height=\"251\" srcset=\"https:\/\/blog.zitnik.si\/wp-content\/uploads\/2022\/08\/add-network-camera.jpg 554w, https:\/\/blog.zitnik.si\/wp-content\/uploads\/2022\/08\/add-network-camera-300x181.jpg 300w\" sizes=\"auto, (max-width: 416px) 100vw, 416px\" \/><\/a><figcaption>Motion EYE add camera dialog.<\/figcaption><\/figure>\n<\/div>\n\n\n<p><strong>RTSP to RTP stream conversion<\/strong><\/p>\n\n\n\n<p>So, my camera RTSP stream was accessible at <code>rtsp:\/\/USER:PASS@IP:554\/live\/ch00_0<\/code>. I already had installed packages VLC that include also <em>cvlc<\/em> command. CVLC is a command-line-based tool for VLC functionalities and is very powerful also to work with video streams. The idea is that we convert the RTSP stream into a RTP stream first. We can achieve this using the following command:<\/p>\n\n\n\n<p><code>cvlc -vvv rtsp:\/\/USER:PASS@IP:554\/live\/ch00_0 --sout \"#rtp{sdp=rtsp:\/\/127.0.0.1:8554}\"<\/code><\/p>\n\n\n\n<p>Note that RTSP link can be different based on an IP camera that you might have. The RTP part of the command specifies where RTP stream will be available &#8211; on a local port in our case.<\/p>\n\n\n\n<p>We also wanted for the stream to be available at the system startup without manual intervention. To support that we configured a service in <em><code>\/etc\/systemd\/system\/cvlc.service<\/code><\/em> and enabled it:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[Unit]\nDescription=cvlc Server\n\n[Service]\nUser=pi\nExecStart=\/usr\/bin\/cvlc -vvv rtsp:\/\/USER:PASS@IP:554\/live\/ch00_0 --sout \"#rtp{sdp=rtsp:\/\/127.0.0.1:8554}\" &amp;\nRestart=on-abort\n\n[Install]\nWantedBy=multi-user.target<\/pre>\n\n\n\n<p>To add this stream to Motion EYE just add a new camera, select <em>Use local stream<\/em>, and enter your local URL. The stream should now be accessible in your app.<\/p>\n\n\n\n<p><strong>Making you Motion EYE interface available over HTTPS<\/strong><\/p>\n\n\n\n<p>By default Motion EYE provides HTTP only support. To enable HTTPS we will use (a) NGINX server as an SSL proxy, and (b) Certbot to provide and maintain Let&#8217;s Encrypt server certificates. Process is briefly available in <a href=\"https:\/\/github.com\/motioneye-project\/motioneye\/wiki\/Running-Behind-Nginx\" target=\"_blank\" rel=\"noreferrer noopener\">the official Github repository<\/a>.<\/p>\n\n\n\n<p>First we install nginx (<code>sudo apt-get install nginx<\/code>) and edit the default confguration in sudo <code>\/etc\/nginx\/sites-available\/default<\/code> as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">server {\n    listen 80 default_server;\n    listen [::]:80 default_server;\n    server_name _;\n    \n    location \/ {\n        proxy_pass http:\/\/127.0.0.1:8765\/;\n        proxy_read_timeout 120s;\n        access_log off;\n    }\n}<\/pre>\n\n\n\n<p>After that we save configuration and restart nginx (<code>sudo service nginx restart<\/code>). Then we install and setup a server certificate (prior to that I expect that you already own a domain with a set public DNS A record that show to your IP):<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt update\nsudo apt install snapd\nsudo snap install core; sudo snap refresh core\nsudo snap install --classic certbot\nsudo ln -s \/snap\/bin\/certbot \/usr\/bin\/certbot\n\nsudo certbot --nginx\n#configure domain and nginx config\n\nsudo certbot renew --dry-run\n#just to check renewal will be okay<\/pre>\n\n\n\n<p>To make sure your server will not be available via other domains or IP delete the default nginx config and leave only the one by certbot. <\/p>\n\n\n\n<p> <\/p>\n<div style=\"margin-top: 0px; margin-bottom: 0px;\" class=\"sharethis-inline-share-buttons\" ><\/div>","protected":false},"excerpt":{"rendered":"<p>Motion EYE project does not support cameras providing RTSP streams only. I had one such camera and wanted to add it along other cameras to my Motion EYE system running on a RPi. RTSP to RTP stream conversion So, my camera RTSP stream was accessible at rtsp:\/\/USER:PASS@IP:554\/live\/ch00_0. I already had&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/blog.zitnik.si\/?p=1909\">Continue reading<span class=\"screen-reader-text\">Motion EYE: Remote SSL + RTSP camera support<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":1910,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[44,45],"class_list":["post-1909","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-free-time","tag-hobby-projects","tag-rpi","entry"],"_links":{"self":[{"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=\/wp\/v2\/posts\/1909","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1909"}],"version-history":[{"count":2,"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=\/wp\/v2\/posts\/1909\/revisions"}],"predecessor-version":[{"id":1913,"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=\/wp\/v2\/posts\/1909\/revisions\/1913"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=\/wp\/v2\/media\/1910"}],"wp:attachment":[{"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1909"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1909"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1909"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}