Skip to content

Cameras: Non RTSP cameras

Hajo Noerenberg edited this page Mar 29, 2023 · 3 revisions

Sometimes it is not possible to run Moonfire NVR with RTSP cameras only. I describe here how I connected a MJPEG camera (basically, it should work with any format supported by ffmpeg):

  1. Install rtsp-simple-server, which is conveniently available as a Docker container. But since a format change of the video stream is necessary, ffmpeg must be added as described here.

  2. Edit rtsp-simple-server.yml and add something similiar to this at the end of the file (line breaks within the ffmpeg command included here for better readability, you have to remove them):

~^(garagedoor)_main:
  runOnDemand: ffmpeg -re -use_wallclock_as_timestamps 1
    -i http://user:pass@10.0.0.123:8080/?action=stream -vsync passthrough
    -filter_complex '[0:v]split=2[inM][inS];[inM]setpts=PTS-STARTPTS[outM];[inS]setpts=PTS-STARTPTS,scale=640:-1[outS]'
    -map '[outM]' -pix_fmt yuv420p -vcodec h264_v4l2m2m -b:v 5M -num_output_buffers 32 -num_capture_buffers 16 -f rtsp rtsp://localhost:$RTSP_PORT/$G1_main
    -map '[outS]' -pix_fmt yuv420p -vcodec h264_v4l2m2m -b:v 2M -f rtsp rtsp://localhost:$RTSP_PORT/$G1_sub
  runOnDemandRestart: yes
  runOnDemandCloseAfter: 120s

This config is a little bit hacky (you might call it clever) as it publishes the _main and _sub stream from within one ffmpeg invocation.

After initial setup, you might want to decrease the ffmpeg log level (ffmpeg -loglevel quiet ...) to not have your disk beeing filled up with logs.

The above snippet is valid for a Raspberry Pi 3B+ and 4 (-vcodec h264_v4l2m2m hardware accelerated codec, you'll need to start the Docker container with --device /dev/video11:/dev/video11 to allow GPU access). Otherwise you have to use something like this (not hardware accelerated):

    -map '[outM]' -vcodec libx264 -tune zerolatency -preset ultrafast -f rtsp rtsp://localhost:$RTSP_PORT/$G1_main
    -map '[outS]' -vcodec libx264 -tune zerolatency -preset ultrafast -f rtsp rtsp://localhost:$RTSP_PORT/$G1_sub
  1. Configure Moonfire NVR to read camera streams from rtsp://rtsp-ss:8554/garagdoor_main and rtsp://rtsp-ss:8554/garagdoor_sub (provided you started the rtsp-ss Docker container with --name="rtsp-ss" within the same Docker network).

For testing purposes you can use any video stream available, e.g. -i https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4 works fine.

Clone this wiki locally