motioneye
motioneye copied to clipboard
RPi Camera 3 compatibility
Will MotionEye, in its current state, be compatible with the new RPi cam 3? https://www.raspberrypi.com/news/new-autofocus-camera-modules/
The new Camera Module 3 is only supported by the modern libcamera software environment and by the libcamera-based Picamera2 beta under Raspberry Pi OS Bullseye, and not by the legacy closed-source camera stack
I just try RPI3b (MotionEyeOS) + RPI Camera 3, It's not work and still find the solution.
I found a way to make it work with the current motioneye version on a pi zero w with the new camera module 3.
First, create a file named motion.sh in /home/pi:
#!/bin/bash
/usr/bin/libcamerify /usr/bin/motion $@
Now, edit your motioneye.conf file (should be in /etc/motioneye) and make sure that the line with motion_binary looks like this:
motion_binary /home/pi/motion.sh
Depending on your debian distribution you might have to also install libcamera-tools with sudo apt-get install libcamera-tools
Now restart motioneye and you can configure your camera as a local camera on /dev/video0
The information that led me to this solution was found here
I found a way to make it work with the current motioneye version on a pi zero w with the new camera module 3.
First, create a file named
motion.shin/home/pi:#!/bin/bash /usr/bin/libcamerify /usr/bin/motion $@Now, edit your
motioneye.shfile (should be in/etc/motioneye) and make sure that the line withmotion_binarylooks like this:motion_binary /home/pi/motion.shNow you can configure your camera as a local camera on
/dev/video0The information that led me to this solution was found here
I tried this but unfortunately it doesn't work. A couple things I've noticed, though.
motioneye.sh is actually motioneye.conf and the correct chmod permissions need to be given to the motion.sh
libcamera-tools has to be installed
I edited my camera-1.conf and changed the video device to /dev/video0 and when running libcamera-hello I'm getting a message that the device is in use...so it feels like it's close!
@MidnightLink I edited my post to correct the file and add the libcamera-tools (I didn't need that as I have the latest debian and it already includes it).
I think your issue is that you can't be running libcamera-hello (or any other application that tries to use the camera) when you start motioneye
Now restart motioneye and you can configure your camera as a local camera on
/dev/video0
Hi @gpambrozio - can you explain how to do this? In MotionEye, Add Camera, I select "Local V4L2 Camera" from the "Camera Type" dropdown, then it lists several options for "Camera". With the module 2 camera, I had to try each one until I found the one that worked, but I can't manually enter a device path.
Also, please can you let me know the exact OS you're running? I tried your fix on Buster & Bullseye with no luck (on an RPi4).
Thanks!
Now restart motioneye and you can configure your camera as a local camera on
/dev/video0Hi @gpambrozio - can you explain how to do this? In MotionEye, Add Camera, I select "Local V4L2 Camera" from the "Camera Type" dropdown, then it lists several options for "Camera". With the module 2 camera, I had to try each one until I found the one that worked, but I can't manually enter a device path.
Best way might be to just pick any cameras, then shutdown motioneye and edit camera-1.conf (probably in /etc/motioneye) and make sure that the videodevice line is videodevice /dev/video0. The start motioneye again.
Also, please can you let me know the exact OS you're running? I tried your fix on Buster & Bullseye with no luck (on an RPi4).
Using bullseye on a pi zero w.
Tried this earlier on a Pi 3B with the latest Bullseye release, fresh install of motioneye, followed the steps above and it works well, I can see the view from the camera via the web interface. For now it doesn't seem to want to let me make any changes, keeps saying "Refresh Recommended" if I try to change resolution or something. I can see the changes reflected in camera-1.conf but the display doesn't change. Will have another poke at it tomorrow, but grateful to have got this far thanks to the previous posts.
Thanks @gpambrozio - I have it working to a point now - I can see the camera's feed. Unfortunately: I don't see all the camera's controls in the Video Device section (like I do with the camera module 2) and performance isn't great.
And like @MisterEmm , If I make any changes via the web app: "An error occurred. Refreshing is recommended." - but refreshing does appear to persist settings
I've also had very similar results running:
libcamera-vid -t 0 --inline -o - | cvlc stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/stream1}' :demux=h264
(https://www.raspberrypi.com/documentation/computers/camera_software.html#libcamera-vid)
Then adding the camera as a network camera in motioneye using:
rtsp://localhost:8554/stream1
then selecting the UDP option that appears.
Neither option seems as quite as good as when I'm using the v2 camera - but maybe I just need to experiment/tweak more. Or hopefully someone with the right skills can update motioneye.
Also, @gpambrozio please could you explain what your motion.sh script does?
@johnm-w motion.sh is a wrapper to make motion use libcamerify as described in this document. Without that /dev/video0 doesn't work as motion expects it.
I tried just changing motion_binary to libcamerify motion but that doesn't work so I created this simple script to trick motioneye.
I have proceeded according to these instructions. The camera can now be integrated into MotionEye and a picture is displayed. https://github.com/motioneye-project/motioneye/issues/2683#issuecomment-1399367885 but unfortunately errors are still written to the log file:
[0:motion] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motioneye/motion.conf
[0:motion] [NTC] [ALL] config_camera: Processing camera config file camera-1.conf
[0:motion] [NTC] [ALL] motion_startup: Logging to syslog
[0:motion] [NTC] [ALL] motion_startup: Motion 4.3.2 Started
[0:motion] [NTC] [ALL] motion_startup: Using default log type (ALL)
[0:motion] [NTC] [ALL] motion_startup: Using log type (ALL) log level (WRN)
[2:22:53.594696843] [21329] INFO Camera camera_manager.cpp:299 libcamera v0.0.3+40-9b860a66
[2:22:53.617144741] [21330] ERROR V4L2 v4l2_device.cpp:352 'imx708_wide': Unable to set controls: Das Gerät oder die Ressource ist belegt
[2:22:53.619075612] [21330] WARN CameraSensorProperties camera_sensor_properties.cpp:205 No static properties available for 'imx708_wide'
[2:22:53.619170872] [21330] WARN CameraSensorProperties camera_sensor_properties.cpp:207 Please consider updating the camera sensor properties database
[2:22:53.665191035] [21330] INFO RPI raspberrypi.cpp:1425 Registered camera /base/soc/i2c0mux/i2c@1/imx708@1a to Unicam device /dev/media3 and ISP device /dev/media0
[2:22:53.665626136] [21329] INFO Camera camera.cpp:841 Pipeline handler in use by another process
[2:22:53.665809312] [21329] ERROR V4L2Compat v4l2_camera.cpp:34 Failed to acquire camera
/home/pi/motion.sh: Zeile 3: 21328 Speicherzugriffsfehler /usr/bin/libcamerify /usr/bin/motion $@
i also couldn't find out yet why the vido is so jerky ... and how I activate the nightvision mode I have also not yet figured out
I also noticed that after starting MotionEye the camera is addressed completely wrong. The settings from the file /usr/share/libcamera/ipa/raspberrypi/imx708_wide.json were all deleted again.
this is how it looks directly after the import.
libcamera-hello --list-camera
Available cameras
-----------------
0 : imx708_wide [4608x2592] (/base/soc/i2c0mux/i2c@1/imx708@1a)
Modes: 'SRGGB10_CSI2P' : 1536x864 [120.13 fps - (768, 432)/3072x1728 crop]
2304x1296 [56.03 fps - (0, 0)/4608x2592 crop]
4608x2592 [14.35 fps - (0, 0)/4608x2592 crop]
After starting MotionEye everything is gone again.
libcamera-hello --list-camera
Available cameras
-----------------
0 : imx708_wide [4608x2592] (/base/soc/i2c0mux/i2c@1/imx708@1a)
Modes: 'SBGGR10_CSI2P' : 1536x864 [30.00 fps - (0, 0)/0x0 crop]
2304x1296 [30.00 fps - (0, 0)/0x0 crop]
4608x2592 [30.00 fps - (0, 0)/0x0 crop]
Service-Status:
systemctl status motioneye.service
● motioneye.service - motionEye Server
Loaded: loaded (/etc/systemd/system/motioneye.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2023-01-28 18:37:00 CET; 6s ago
Main PID: 6675 (meyectl)
Tasks: 14 (limit: 1934)
CPU: 4.347s
CGroup: /system.slice/motioneye.service
├─6675 /usr/bin/python2 /usr/local/bin/meyectl startserver -c /etc/motioneye/motioneye.conf
├─6710 /bin/bash /home/pi/motion.sh -n -c /etc/motioneye/motion.conf -d 5
├─6711 /usr/bin/motion -n -c /etc/motioneye/motion.conf -d 5
└─6735 /usr/bin/python2 /usr/local/bin/meyectl startserver -c /etc/motioneye/motioneye.conf
Jan 28 18:37:02 raspberrypi motion[6711]: [0:motion] [NTC] [ALL] motion_startup: Logging to syslog
Jan 28 18:37:02 raspberrypi motion[6711]: [0:motion] [NTC] [ALL] motion_startup: Motion 4.3.2 Started
Jan 28 18:37:02 raspberrypi motion[6711]: [0:motion] [NTC] [ALL] motion_startup: Using default log type (ALL)
Jan 28 18:37:02 raspberrypi motion[6711]: [0:motion] [NTC] [ALL] motion_startup: Using log type (ALL) log level (WRN)
Jan 28 18:37:03 raspberrypi motion[6711]: [1:ml1:Camera1] [ERR] [VID] v4l2_fps_set: Fehler beim Einstellen der FPS. Rückkehrcode -1
Jan 28 18:37:04 raspberrypi meyectl[6675]: INFO: cleanup started
Jan 28 18:37:04 raspberrypi meyectl[6675]: INFO: wsswitch started
Jan 28 18:37:04 raspberrypi meyectl[6675]: INFO: tasks started
Jan 28 18:37:04 raspberrypi meyectl[6675]: INFO: mjpg client garbage collector started
Jan 28 18:37:04 raspberrypi meyectl[6675]: INFO: server started
unfortunately I could not get my camera module 3 to work via any of the suggestions above with a raspberry pi 4 / b running bullseye. Really hope the new cameras will be supported without workarounds in motioneye soon.
@gpambrozio It works ! Many thanks !
My setup :
- RPI 4 with 1 GB RAM, 16 GB SD-Card
- RPI OS, Rasbian GNU/Linux 11 (Bullseye)
- Motioneye vs 0.42.1, Motion vs 4.3.2
- Raspberry Pi Camera Module 3 NoIR
Some additional advices/observations:
- after adding Camera1 in Motioneye make sure you select the upper 'Unicam'
- note that the 'camera-1.conf' file does not pop-up in /etc/motioneye sooner than after adding that Camera1,
- then edit the 'camera-1.conf' as in the above instructions
- and... you can additionally improve the picture-quality dramatically by editing 'stream_quality' and 'movie_quality' in 'camera-1.conf'(I both increased them to 150, perfect quality !)
- and the infrared also works, and even automatically :-)
For those who have gotten this workaround to work:
- Are you using a 64 bit or 32 bit OS version of Bullseye?
- Did you enable legacy camera support in raspi-config?
- Are you adding the camera as V4L2 or MMAL?
- Are you using the main branch of Motioneye (python2) or the Dev branch (python3)?
I just keep getting the following errors no matter what i try:
[1:ml1:Camera1] [ERR] [VID] v4l2_device_capability: Not a V4L2 device?
[1:ml1:Camera1] [ERR] [VID] vid_start: V4L2 device failed to open
Update: This workaround worked on the 32-bit version of Bullseye using the Dev branch. Legacy camera support was not needed. Cameras were added as V4L2.
Hey together, what am I doing wrong?
- Raspberry Pi 3 B+
- Bullseye OS 32-bit lite
- installing motioneye according to the official instructions
- follow the instructions from @gpambrozio
- creating motion.sh an setting up chmod (sudo chmod +x motion.sh)
- editing
motioneye.confby following the instructions. - start motioneye and added a V4L2 Camera
- stop motioneye an edit
camera-1.conf->videodevice /dev/video0 - start motioneye ...
but no picture in the preview.
Camera works with Raspberry Pi 4, Bullseye OS 32-bit lite and motionEye (dev) up to 4608 / 2592 (legacy camera not enabled). Only one issue, neither storage (/var/lib/motioneye/Camera1 empty) nor FTP upload seems to work. Anybody facing same issue?
Hey together, what am I doing wrong?
Raspberry Pi 3 B+
Bullseye OS 32-bit lite
installing motioneye according to the official instructions
follow the instructions from @gpambrozio
- creating motion.sh an setting up chmod (sudo chmod +x motion.sh)
- editing
motioneye.confby following the instructions.- start motioneye and added a V4L2 Camera
- stop motioneye an edit
camera-1.conf->videodevice /dev/video0- start motioneye ...
but no picture in the preview.
Did you install the motioneye dev branch? https://github.com/motioneye-project/motioneye/tree/dev
Also, did you install libcamera-tools? sudo apt install libcamera-tools
Hey together, what am I doing wrong?
Raspberry Pi 3 B+
Bullseye OS 32-bit lite
installing motioneye according to the official instructions
follow the instructions from @gpambrozio
- creating motion.sh an setting up chmod (sudo chmod +x motion.sh)
- editing
motioneye.confby following the instructions.- start motioneye and added a V4L2 Camera
- stop motioneye an edit
camera-1.conf->videodevice /dev/video0- start motioneye ...
but no picture in the preview.
Did you install the motioneye dev branch? https://github.com/motioneye-project/motioneye/tree/dev Also, did you install libcamera-tools?
sudo apt install libcamera-tools
Hey @notabotscott
thank you very much, the wrong installation was the problem. I had already installed the libcamera tools. But i had to install the motioneye dev branch.
Thank you for this workaround. I was able to get my camera module 3 working fine except for adding parameters in the config. Is there any way to change brightness, exposure and lens-position? I've tried adding them different ways in the config file and nothing seems to work. Any help would be greatly appreciated.
None of these worked for me on a rpi4 running latest 64 bit os. Really wish I could use this new camera.
I have few cameras lying idle because of the issue and lack of time to dig into the issues.
I never got the libcamerify to work but still feel it should have. Might give it a new try one day. Anyways the motion project is old and will never support the new cameras using libcamera. MotionEye should maybe start looking at transitioning to motionPlus (when python3 has reached maturity) as it seems a replacement wich is actively developed. motionPlus works with libcamera.
I found this solution online and you need screen and ngnix installed. I created a shell script to start by boot in crontab. This has been stable now for some months. This is the first time I ever used ngnix. The two processes use maybe 5% CPU in average. It can support a good FPS but I keep it low for motion detection.
# cat /root/start_rpicam3_stream.sh
#!/bin/bash -x
mkfifo /root/stream
chmod 777 /root/stream
screen -l -dmS libcamera /usr/bin/libcamera-vid -t 0 --width 1920 --height 1080 --codec h264 -n --hdr 1 --profile=high --framerate 5 -o /root/stream
screen -l -dmS ffmpeg /usr/bin/ffmpeg -y -i /root/stream -s 1920x1080 -r 5 -c:v copy -b:v 1500k -maxrate 5000k -bufsize 10000k -g 60 -f flv rtmp://localhost/live/stream
# crontab -l
# Edit this file to introduce tasks to be run by cron.
# m h dom mon dow command
@reboot sleep 60 && /root/start_rpicam3_stream.sh
# cat /etc/nginx/nginx.conf
rtmp {
server {
listen 1935;
allow publish 127.0.0.1;
deny publish all;
timeout 60s;
notify_method post;
chunk_size 8192;
application live {
live on;
record off;
}
}
}
- MotionEye Camera device/URL
netcam_url rtmp://localhost/live/stream
Change the FPS to what you want. 1920x1080 is maximum resolution for the RPI hw codec as I think it's used here.
@strips are you using this as a replacement for motioneye or 'just' (great idea :) ) as a streaming source / camera FOR motioneye?
@mgrn0, I'm using this with motionEye. Effectively creating a network stream from the camera and configuring motionEye to use the stream as a source. All running on the same RPI4.
I'm kinda confused on what you are using screen for here and why it's needed. But I like the concept of connecting to it as a network stream. That's a great idea I'll play with this this weekend.
@bigOconstant screen is a simple (ugly) way to run a background process. Could probably use nohup or set up proper daemon instead. I tried nohup but one of the commands did not like the limited environment and went back to screen.
I got libcamerify to partially work by compiling Motion from source. My next issue was that MotionEye did not seem to detect the running process of Motion when using the wrapper and got a lot of crash loops. So close, I decided to see if I could fix this in the code to eliminate the need for an external wrapper script. In my own fork I have implemented support for libcamerify and it can be configured in motioneye.conf. So far it seems to work pretty good. The only issue seems to be setting parameters for the camera. I'll probably create a PR for my fix. Anyways the code is here: https://github.com/strips/motioneye/tree/feature/libcamerify
@strips Thanks for the instructions for libcamera+ffmpeg combo as I couldn't get the libcamerify method to work with camera module 3 (1.1 worked fine) and what's more, with libcamerify there is no way(?) to set camera parameters which is a must in my use case.
I had to add -re parameter to ffmpeg -y -re -i /root/stream -s 1920x1080 -r 5 -c:v copy -b:v 1500k -maxrate 5000k -bufsize 10000k -g 60 -f flv rtmp://localhost/live/stream as otherwise ffmpeg was not reading the input in real time, reached end of file and quit.
One question about the named pipe (fifo) though - it seems this file (/root/stream) keeps increasing in size. How did you solve this?
@github-0 np! I found the link where I found the workaround: https://www.wetransco.de/debian-bullseye-libcamera-and-motion-on-a-raspberry-pi-with-the-new-camera-module-v3-a-great-workaround/
Using rtsp-simple-server should/could be a much simpler approach. I tested this for an hour before switching to libcarmerify and it worked at least as well. The advantage is that it's only one binary/command to run. If needed I could post the config file I made.
Thanks @strips I got it to work with your script in the same fashion and your 60 second sleep make it work after a minute on restart which is great.
Full instructions for others would involve, starting from blank rasbian os, installing nxinx, follow the install motion-eye instructions from dev branch, adding the nginx config file and then doing whats in the above comment and it works.