{"id":390,"date":"2020-10-25T15:46:00","date_gmt":"2020-10-25T15:46:00","guid":{"rendered":"https:\/\/francisfisher.me.uk\/problem\/?p=390"},"modified":"2020-10-25T16:57:36","modified_gmt":"2020-10-25T16:57:36","slug":"raspberry-pi-camera-shinobi-cctv","status":"publish","type":"post","link":"https:\/\/francisfisher.me.uk\/problem\/2020\/raspberry-pi-camera-shinobi-cctv\/","title":{"rendered":"Raspberry Pi camera &#038; Shinobi CCTV"},"content":{"rendered":"\n<p>Raspberry Pis make for really good HD CCTV cameras as they're cheap, small and have wifi in the newer iterations. There seem to be two good CCTV recording packages at the moment - Shinobi &amp; MotionEyes. It took some effort to get Shinobi to communicate with the camera on my Raspberry Pi, so this post records what I had to do, for posterity.<\/p>\n\n\n\n<p>If you search on the internet about RaspberryPi cameras and Shinobi you find a bunch of posts talking about setting up an RTSP stream for Shinobi to connect to. And on the Shinobi discord, a developer pointed to <a href=\"https:\/\/gitlab.com\/Shinobi-Systems\/shinobi-ip-camera\">https:\/\/gitlab.com\/Shinobi-Systems\/shinobi-ip-camera<\/a>. None of these instructions worked - I think they may have been for an older version of Raspbian. So firstly lets go through the software versions and hardware versions that I'm dealing with.<\/p>\n\n\n\n<p>The hardware is a Raspberry Pi 3, and a Raspberry Pi ZeroW. Both of these have built in wifi which makes things easier. With these I'm using official Raspberry Pi cameras. I'm using the latest version of Raspbian at the time of writing - Raspbian GNU\/Linux 10, and <a href=\"https:\/\/gitlab.com\/Shinobi-Systems\/Shinobi\/-\/releases\/ocean-1\">Shinobi ocean-1<\/a>.<\/p>\n\n\n\n<p>What eventually worked for me was adapted from a couple of web pages, particularly <a href=\"https:\/\/gist.github.com\/neilyoung\/8216c6cf0c7b69e25a152fde1c022a5d\">https:\/\/gist.github.com\/neilyoung\/8216c6cf0c7b69e25a152fde1c022a5d<\/a>, and involved gst-rpicamsrc and gst-rtsp-server which contained the test-launch programme.<\/p>\n\n\n\n<ol><li>Download and build <a href=\"https:\/\/github.com\/thaytan\/gst-rpicamsrc\">https:\/\/github.com\/thaytan\/gst-rpicamsrc<\/a>. In the future this will be part of gstreamer (from version 1.18) so you won't need to do this step any more.<\/li><li>Find out your gstreamer (gst) version e.g. with <code>apt search libgstreamer<\/code>. At the time of writing this is libgstreamer1.0-0\/stable 1.14.4-1 armhf. You then need to download the version of gst-rtsp-server that matches your libgstreamer1.0 version. So I downloaded gst-rtsp-server-1.14.4 from <a href=\"https:\/\/github.com\/GStreamer\/gst-rtsp-server\">https:\/\/github.com\/GStreamer\/gst-rtsp-server<\/a> and build that.<\/li><li><code>sudo apt install gstreamer1.0-plugins-ugly gstreamer1.0-plugins-bad gstreamer1.0-plugins-rtp<\/code><\/li><li>gst-rtsp-server provides a utility called test-launch. It sets up an rtsp server. I manually ran this with <code>test-launch ( rpicamsrc bitrate=8000000 awb-mode=auto preview=false rotation=180 ! video\/x-h264, width=960, height=540, framerate=10\/1 ! h264parse ! rtph264pay name=pay0 pt=96 )<\/code>. This command had a resolution for a v1 camera. If you use a v2 camera you will want to choose a different resolution. I found <a href=\"https:\/\/picamera.readthedocs.io\/en\/release-1.12\/fov.html#camera-modes\">this page<\/a> to be useful for understanding the modes available.<\/li><li>I then was able to configure Shinobi to connect to rtsp:\/\/CAMERA_IP:8554\/test.<\/li><li>The final setup was to install test-launch as a permanent background task in systemd. Put a file with the following contents into \/etc\/systemd\/system called e.g. cam-stream.service then run <code>systemctl start cam-stream &amp;&amp; systemctl enable cam-stream<\/code>.<\/li><\/ol>\n\n\n\n<p><code>[Unit]<br>Description=auto start cam stream<br>After=multi-user.target<br>[Service]<br>Type=simple<br>ExecStart=\/home\/xxx\/bin\/test-launch ( rpicamsrc bitrate=8000000 awb-mode=auto preview=false rotation=180 ! video\/x-h264, width=960, height=540, framerate=10\/1 ! h264parse ! rtph264pay name=pay0 pt=96<br>User=xxx<br>WorkingDirectory=\/home\/xxx\/shinobi<br>Restart=on-failure<br>[Install]<br>WantedBy=multi-user.target<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Raspberry Pis make for really good HD CCTV cameras as they're cheap, small and have wifi in the newer iterations. There seem to be two good CCTV recording packages at the moment - Shinobi &amp; MotionEyes. It took some effort to get Shinobi to communicate with the camera on my Raspberry Pi, so this post [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[3],"tags":[8,7,6,5,9],"_links":{"self":[{"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/posts\/390"}],"collection":[{"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/comments?post=390"}],"version-history":[{"count":10,"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/posts\/390\/revisions"}],"predecessor-version":[{"id":401,"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/posts\/390\/revisions\/401"}],"wp:attachment":[{"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/media?parent=390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/categories?post=390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/tags?post=390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}