[solved] Raspberry Pi (Zero)/3B as Cam with PiCam3 possible? - yes

Hey there,

a few weeks ago, I bought a Reolink Cam and integrated it into my setup.

Now i’m trying to build an own cam, based on Raspberry Pi and a PiCam 3, but I cannot get a working setup.
I tried MotioneyeOS, but it was not able to catch the stream, since it doesn’t work with the PiCam3 (afaik).
Currently, i’m experimenting with “raw” libcamera-vid
But also no luck till now.

I would like to have a “dump” cam, that streams via rtsp or anything else, into HA / Frigate.

Anybody here with a working setup like that? Some hints from working concepts would be nice.
Thank you.

Update #1: I was able to create a stream and consume it in VLC with libcamera-vid, but it was very instable and i was not able to get it into HA.

Update#2: I found two ways to make it work:

  1. I was able to get it work with an mediamtx docker container for pi
  2. It is possible with motioneye (dev branch, which supports python3) on bullseye and a workaround, currently working on Pi 3B, i will test it on Zero later

If everything works, i will add more details how i got it to work, maybe somebody can use the info :slight_smile:

Update #3 - Solution

Motioneye: The motioneye solution does not work good with Pi Zero (i don’t have a Zero 2). Also, the workaround seems to “brick” the WebGui and a had a lot of trouble with that. The last argument is the high cpu usage by motion and motioneye. I would not recommend that way!

got2rtc: During my research i have found another solution. go2rtc is easy to setup and can be used in a few seconds by creating a .yaml and use something like exec:libcamera-vid -t 0 --inline --listen -o -
This will use the PiCam and create different streams you can use anywhere else.
The downside of this solution is that you are not able to add a timestamp so easily. At least i was not able to do it, since you would need to use ffmpeg for that. Also, i read that this way would increase the CPU load a lot, which is not good with a Pi Zero

mediamtx: At the end i went with mediamtx, but without a docker installation. It has default support for PiCam3. You only have to change

paths:
  all:
    source:publisher

to:

paths:
  cam:
    source: rpiCamera

and it already works. If you want to add a timestamp, just change

rpiCameraTextOverlayEnable: true  # This is false by default
rpiCameraTextOverlay: '%Y-%m-%d %H:%M:%S - Cam1' # This is there by default

That’s it, works good for me. I will test this now long term and see what’s going to happen.

Found my own solution:
Motioneye: The motioneye solution does not work good with Pi Zero (i don’t have a Zero 2). Also, the workaround seems to “brick” the WebGui and a had a lot of trouble with that. The last argument is the high cpu usage by motion and motioneye. I would not recommend that way!

got2rtc: During my research i have found another solution. go2rtc is easy to setup and can be used in a few seconds by creating a .yaml and use something like exec:libcamera-vid -t 0 --inline --listen -o -
This will use the PiCam and create different streams you can use anywhere else.
The downside of this solution is that you are not able to add a timestamp so easily. At least i was not able to do it, since you would need to use ffmpeg for that. Also, i read that this way would increase the CPU load a lot, which is not good with a Pi Zero

mediamtx: At the end i went with mediamtx, but without a docker installation. It has default support for PiCam3. You only have to change

paths:
  all:
    source:publisher

to:

paths:
  cam:
    source: rpiCamera

and it already works. If you want to add a timestamp, just change

rpiCameraTextOverlayEnable: true  # This is false by default
rpiCameraTextOverlay: '%Y-%m-%d %H:%M:%S - Cam1' # This is there by default

That’s it, works good for me. I will test this now long term and see what’s going to happen.

1 Like

@Suzabi How did you manage to change the parameters? when i try to change it nothing happens on the stream. Do you have it also setup as a server? so that it starts automatic when the pi gets powered on?

Sorry for the late response. Hopefully it will help somebody…

Yes i got it as a server. I followed the docs here (Start on boot part): GitHub - bluenviron/mediamtx: Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.

Also, make sure that you are pointing to your .yml file, where your config is in, and you have set up your permission correctly on that file

But at the end i created a run_mediamtx_server.sh with the follwowing code.

#!/bin/bash
/home/administrator/mediamtx /home/administrator/mediamtx.yml

this script starts the server with the config file.
Then i created a service

/etc/systemd/system/mediamtx.service

with this inside

[Unit]
Description=Media MTX

[Service]
User=administrator
WorkingDirectory=/home/administrator
ExecStart=/home/administrator/run_mediamtx_server.sh
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

and then register the service as in the docs

This is not an optimal solution, but at the end i was simply lazy…

@suzabi Thank you for reporting this! I am just curios if you have tried the motionEyeOS (burned in the sd) or you used rapsbian with the motion and motioneye libs?

Thank you!