Cameras: Non RTSP cameras - scottlamb/moonfire-nvr GitHub Wiki
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):
-
Install rtsp-simple-server, which is conveniently available as a Docker container. But since a format change of the video stream is necessary,
ffmpegmust be added as described here. -
Edit
rtsp-simple-server.ymland add something similiar to this at the end of the file (line breaks within theffmpegcommand included here for better readability, you have to remove them):
~^(garagedoor)_main:
runOnDemand: ffmpeg -re -use_wallclock_as_timestamps 1
-i http://user:[email protected]: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
- Configure Moonfire NVR to read camera streams from
rtsp://rtsp-ss:8554/garagdoor_mainandrtsp://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.