Shinobi on the Raspberry Pi 3 B+ (tips and suggestions)



  • Shinobi on the Raspberry Pi 3 B+

    The Raspberry Pi is a $35 single board computer that runs on a 64-bit ARM processor. It uses the Broadcom BCM2835 SoC which includes hardware-accelerated h264 encoding/decoding, making it a great choice for running a small Shinobi setup with network h264 cameras.

    This "guide" will walk you through my setup and provide some tips if you want to use the RPI for this purpose.

    The setup

    My setup includes 4 cameras: 2x [email protected], and 2x [email protected] I have them monitoring for motion and recording. The RPI is able to handle this workload with surprisingly little power usage.

    In order for this setup to work, there's a few conditions that must be met:

    1. No transcoding. It's simply too CPU intensive even with hardware-accelerated h264_omx encoder. For any recording/streaming you'll need to set the video codec to "copy" (or possibly the jpeg API).
    2. Depending on the camera quality settings, you'll need to bump the GPU memory share up to 256MB. Even to me this seemed too high, but without it I was getting mmal decoding errors with more than 2 [email protected] NVR camera.
    3. For any decoding you'll need to use the hardware-accelerated h264_mmal codec. Without specifying this codec there will be too much CPU usage. Using MMAL ensures that the heavy lifting of deciding the h264 stream is done on the GPU.
    4. Real 2.5a power supply. Your RPI needs all of it.
    5. (Optional) Active cooling. My RPI case has a small fan hooked up the 3v power supply. I have small heatsinks attached to the SoC.

    Configuration

    The default ffmpeg binary installed from apt includes all of the necessary codecs to use RPI's GPU for hardware acceleration. There's no need to do any compiling or ffmpeg, just get it from apt and you're done.

    # ffmpeg
    ffmpeg version 3.2.10-1~deb9u1+rpt2 Copyright (c) 2000-2018 the FFmpeg 
    
    # The encoder to use (if any -- see comment about "copy")
    $ ffmpeg -encoders | grep omx
     V..... h264_omx             OpenMAX IL H.264 video encoder (codec h264)
    
    # The decoder to use
    $ ffmpeg -decoders | grep mmal
     V..... h264_mmal            h264 (mmal) (codec h264)
     V..... mpeg2_mmal           mpeg2 (mmal) (codec mpeg2video)
     V..... mpeg4_mmal           mpeg4 (mmal) (codec mpeg4)
     V..... vc1_mmal             vc1 (mmal) (codec vc1)
    

    Configuring Shinobi

    Shinobi is already configured to support the Raspberry Pi's native encoders/decoders. Select yes for hardware acceleration. Leave the HWAccel option as auto and select H.264 (Raspberry Pi) as the decoder.

    This will use the hardware-accelerated h264_mmal codec.

    For streaming/output I highly recommend you set it to copy to save yourself the CPU cycles of transcoding. If you need to encode in h264, make sure to use the h264_omx codec so that it's hardware accelerated.

    Another option for transcoding is simply to setup a cron to do the transcoding in the background with low CPU affinity.

    That's about it as far as configurations go.

    Storage

    You basically have three options: root storage, attached storaged, and network-attached storage.

    The raspberry pi's main storage is micro SD. You can use the root storage as your primary storage if you're careful about space and set the appropriate video expirations.

    You can attach storage via the USB interface. Be careful with additional power draw if your device is unpowered.

    The last option is to use a network-attached storage device. This can be a NAS or something similar. This method is the most flexible if the hardware is available to you, such as a NAS server.

    Troubleshooting

    mmal encoding errors

    The most common problem I encountered was mmal encoding errors. If your cameras are restarting because of these errors, bump up the available memory to the GPU. You may also need to downscale the quality/bitrate of your cameras.

    Unstable Pi / reboots

    Make sure you're using a 2.5a (or above) power supply. Most power supplies do not supply 2.5a. Usually ones that are marketed for iPads or tablets will supply the amperage, but you must check the back of your adapter to see what its rating is.

    Depending on your setup (and how hard you're pushing your Pi), you may need active cooling. You can also try adding a heatsink to the CPU/GPU SoC.

    Slow / sluggish performance

    If you're using the h264_mmal codec with a [email protected] camera, it takes about 100% of a single CPU. If you're seeing higher CPU usage (such as 200-250%) you're probably not using the codec or something is else is misconfigured.

    You can check by running ps aux | grep ffmpeg and taking note of the setting just before the -i rtsp://... line. It should say -c:v h264_mmal.

    $ sudo ps aux | grep ffmpeg
    ffmpeg ... -c:v h264_mmal -i rtsp://....
    


  • I've lastest raspbian stretch lite and Shinobi installed through the Hard Way mode. Everything is working, but I'm not able to see Raspberry section on Video decoder option. Did you do something more?


 

Looks like your connection to Shinobi Forum was lost, please wait while we try to reconnect.