Sign inSign up

gagara/shinobi-arm64

By gagara

Updated over 4 years ago

Shinobi CCTV for aarch64 with hardware acceleration support for RPi and Rockchip boards

Image
4

10K+

gagara/shinobi-arm64 repository overview

Shinobi CCTV for aarch64

Shinobi is open source CCTV solution. This image supports hardware acceleration for Raspberry Pi (MMAL and V4L2 M2M) as well as Rockchip (MPP) based boards (e.g. Rock64).

Dockerfile

This Dockerfile is used to build images.

Repository

It is based on this fork of official Shinobi.

Run

docker run -d \
    --name="shinobi" \
    --privileged \
    -p "8080:8080/tcp" \
    -v "/dev/shm/Shinobi/streams":"/dev/shm/streams":"rw" \
    -v "/dev":"/dev":"rw" \
    -v "/var/cache/shinobi/config":"/config":"rw" \
    -v "/var/cache/shinobi/customAutoLoad":"/home/Shinobi/libs/customAutoLoad":"rw" \
    -v "/var/cache/shinobi/database":"/var/lib/mysql":"rw" \
    -v "/var/cache/shinobi/videos":"/home/Shinobi/videos":"rw" \
    -v "/var/cache/shinobi/plugins":"/home/Shinobi/plugins":"rw" \
    -v "/etc/localtime":"/etc/localtime":"ro" \
    gagara/shinobi-arm64:latest

or simply use this docker-compose file like

docker-compose -f docker-compose-aarch64.yaml up

It is good idea to mount some external SSD/HDD to /var/cache/shinobi before running it (it stores videos, images, DB files there)

Build

To build image yourself, checkout repository and switch to aarch64 branch

git clone https://gitlab.com/gagara/Shinobi.git
cd Shinobi/
git checkout aarch64

then build image

docker build -t gagara/shinobi-arm64 -f Dockerfile.aarch64 .

Note: Latest images are based on Gentoo, thus building everything from scratch may take quite some time and resources. To optimize this process it is possible to pass space-separated list of Gentoo's binhosts as docker build argument. e.g.:

docker build -t gagara/shinobi-arm64 --build-arg BINHOST="https://packages.server.com" -f Dockerfile.aarch64 .

By default https://packages.genpi64.com/ is used as binhost.

How to configure Shinobi with hardware acceleration

Raspberry Pi

With RPi boards there are two options:

  • MMAL
  • V4L2 M2M
MMAL

Supports h264, mpeg2, mpeg4, vc1 decoders.

Note: MMAL is not officially supported on aarch64 so far. If you have any troubles with it consider switching to v4l2m2m which is supported and has even better performance.

  1. Make sure your host has DRM support enabled. DRM provides devices at /dev/dri (e.g. /dev/dri/card0). If you don't have such devices available then read the docs of your distro on how to enable it. Usually you need to have dtoverlay=vc4-fkms-v3d enabled in your config.txt and enough "video RAM" -- gpu_mem=128 at least.
  2. In Shinobi go to Monitor settings:
  • Input
    • Accelerator - Yes
    • Acceleration Engine - DRM
    • Video Decoder - H.264 (Raspberry Pi )
    • HWAccel Device - /dev/dri/card0
V4L2 M2M

Supports h263, h264, h265, mpeg1, mpeg2, mpeg4, vc1, vp8, vp9 decoders and h263, h264, h265, mpeg4, vp8 encoders. Officially supported on aarch64!

  1. Make sure your host has v4l2 enabled. You should have devices like /dev/video10, /dev/video11 available on your system. If you don't have them, then read the docs for your distro on how to enable it.
  2. In Shinobi go to Monitor settings:
  • Input
    • Accelerator - Yes
    • Acceleration Engine - Auto
    • Video Decoder - V4L2 mem2mem H.264 (Raspberry Pi)
    • HWAccel Device - (empty)

Note: Hardware acceleration on RPi has series of limitations/drawbacks:

  • Both MMAL and v4l2m2m is able to handle resolution up to 1080p. Thus if you have 3-4MP camera you will have to shrink resolution to 1080p or less on your camera.
  • Hardware decoders require a lot of "video RAM". To handle one 1080p stream you will need at least 128 Mb. Having that on RPi4 max gpu_mem setting is 512, you won't be able to handle more that 4 streams in parallel.
  • Experiments shows that performance of both decoders drops significantly when you have several processes running in parallel (i.e. connect several cameras). For example on my RPi4 single ffmpeg process (handling 1080p h264 stream) consumes ~10% of single CPU core. But when I run 4 ffmpeg-s in parallel they consume ~50% of single CPU core each!

Fortunately Shinobi has great support of sub-streams handling. So if your camera has substreams (usually low resolution) you can use it with Shinobi and it will dramatically improve performance without any quality/experience loses. Read next section about this.

Use Sub-streams with Shinobi

In most cases for motion detection you don't need full resolution, fps, etc from your camera. By default Shinobi uses 640x480, 2 fps, grayscale picture which is perfectly enough. If you grab 1080p, 25fps from your camera then a lot of CPU/GPU time is required to transcode it to lower quality for Motion Detection engine. Most modern cameras support several streams. Main stream -- full resolution, max quality, and sub-streams -- low resolution. You can configure Shinobi to use e.g. main stream for recording and substream for motion detection and streaming (live view). See this doc for details about additional streams aka Input Feeds in shinobi. For example you can configure it like this:

  • In Connection section (aka main Input Feed) use camera's sub-stream. It will have index 0
  • In additional Input Map: 1 section use main camera stream. It will have index 1.
  • In Stream section use Input Feed 0
  • In Global detector settings section use Input Feed 0
  • In Traditional recording section use Input Feed 1

It is reasonable to configure sub-stream resolution in your camera to match with resolution you use in Global detector settings.

This kind of setup on my RPi4 with 6 cameras (3MP, h264) keeps CPU load under 20%.

Rockchip

Rockchip has very powerful support of video hardware decoding (MPP).

MPP

Supports h264, h265, vp8, vp9 decoders.

  1. Make sure your host has DRM support enabled. DRM provides devices at /dev/dri (e.g. /dev/dri/card0). If you don't have such devices available then read the docs of your distro on how to enable it.
  2. In Shinobi go to Monitor settings:
  • Input
    • Accelerator - Yes
    • Acceleration Engine - DRM
    • Video Decoder - H.264 (RockChip)
    • HWAccel Device - /dev/dri/card0

On my test system (Rock64 board) with 6 3MP (h264) cameras (in full resolution!!!) keeps CPU load under 40%. Which is way better than on RPi.

You can benefit even more if you use Sub-streams in Shinobi described above.

Tag summary

Content type

Image

Digest

Size

1.4 GB

Last updated

over 4 years ago

docker pull gagara/shinobi-arm64