Wednesday, May 17, 2017

Setting Up RTSP Server in Raspberry PI and Zoneminder

I have been testing at Raspberry PI Zero W as a security camera connected to ZoneMinder for few weeks and it has been working perfectly. No drop frames or delays or cables or dongles or anything. Just a Pi Zero W, Camera Module and Power Supply.

I used the following links as reference:

Prepare Raspberry PI SD Card with Raspbian Jessie Lite:

dd bs=4M if=Desktop/2017-04-10-raspbian-jessie-lite.img of=/dev/sdX


Setup Raspberry PI:

  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo raspi-config
    • Change Hostname to something meaningful
    • Localisation Options -> Change Locale
    • Localisation Options -> Change Timezone
      • Interfacing Options -> P1 Camera to Enable
      • Interfacing Options -> P2 SSH (optional)
      • Advance Options -> A1 Expand Filesystem
      • Advance Options -> Memory Split (128M or 256M)
    • Set WIFI
    sudo iwlist wlan0 scan (optional just to scan)
    sudo wpa_passphrase "YOUR_SSID" "YOUR_PASSWORD" >> /etc/wpa_supplicant/wpa_supplicant.conf

      • Delete plain text password entry from wpa_supplicant.conf  (optional)
    sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
    • Add Camera module to list of modules to start at boot
    sudo echo "bcm2835-v4l2" >>  /etc/modules-load.d/picamera.conf

    Install Dependencies:

    sudo apt-get install git cmake
    wget http://www.live555.com/liveMedia/public/live555-latest.tar.gz -O - | tar xvzf -
    cd live
    ./genMakefiles linux
    sudo make CPPFLAGS=-DALLOW_RTSP_SERVER_PORT_REUSE=1 install

    Install v4l2rtspserver:

    git clone https://github.com/mpromonet/v4l2rtspserver
    cd v4l2rtspserver
    cmake .
    make
    sudo make install


    Systemd Startup Script (Thank you Andrew):

    In order to get v4l2rtspserver to start automatically after boot, I created a systemd service file. Create the file /etc/systemd/system/v4l2rtspserver.service and add the following contents. Adjust i_frame_period and -F to the frame rate that you want to record.

    # systemd configuration for v4l2rtspserver
    # /etc/systemd/system/v4l2rtspserver.service
    [Unit]
    Description=v4l2rtspserver rtsp streaming server
    After=network.target
    [Service]
    #ExecStartPre=/usr/bin/v4l2-ctl --set-ctrl vertical_flip=1
    #ExecStartPre=/usr/bin/v4l2-ctl --set-ctrl rotate=90
    ExecStartPre=/usr/bin/v4l2-ctl --set-ctrl h264_i_frame_period=4
    ExecStart=/usr/local/bin/v4l2rtspserver -F 4 -W 1920 -H 1080
    #ExecReload=/bin/kill -HUP $MAINPID
    Type=simple
    User=root
    Group=video
    Restart=always
    [Install]
    WantedBy=multi-user.target

    Let's give it a try:

    sudo systemctl enable v4l2rtspserver
    sudo systemctl start v4l2rtspserver


    ZoneMinder Configuration:

    • Source Type: Remote
    • Remote Protocol: RTSP
    • Remote Method: RTP/Unicast
    • Remote Host Name: Hostname or IP
    • Remote Host Port: 8554
    • Remote Host Path: /unicast
    • Capture Width: 1920
    • Capture Height: 1080




    No comments: