Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPi Camera 3 compatibility #2683

Open
Firesphere opened this issue Jan 9, 2023 · 79 comments
Open

RPi Camera 3 compatibility #2683

Firesphere opened this issue Jan 9, 2023 · 79 comments

Comments

@Firesphere
Copy link

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

@hotducker
Copy link

I just try RPI3b (MotionEyeOS) + RPI Camera 3, It's not work and still find the solution.

@gpambrozio
Copy link

gpambrozio commented Jan 21, 2023

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

@MidnightLink
Copy link

MidnightLink commented Jan 22, 2023

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.sh file (should be in /etc/motioneye) and make sure that the line with motion_binary looks like this:

motion_binary /home/pi/motion.sh

Now you can configure your camera as a local camera on /dev/video0

The 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!

@gpambrozio
Copy link

gpambrozio commented Jan 22, 2023

@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

@johnm-w
Copy link

johnm-w commented Jan 26, 2023

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!

@gpambrozio
Copy link

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.

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.

@MisterEmm
Copy link

MisterEmm commented Jan 27, 2023

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.

@johnm-w
Copy link

johnm-w commented Jan 27, 2023

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?

@gpambrozio
Copy link

@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.

@ReneMuetti
Copy link

ReneMuetti commented Jan 28, 2023

I have proceeded according to these instructions. The camera can now be integrated into MotionEye and a picture is displayed.
#2683 (comment)
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

@mgrn0
Copy link

mgrn0 commented Feb 11, 2023

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.

@MaRaGaWa
Copy link

MaRaGaWa commented Mar 14, 2023

@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 :-)

@notabotscott
Copy link

notabotscott commented Mar 22, 2023

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

@notabotscott
Copy link

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.

@B4n4n3
Copy link

B4n4n3 commented Mar 26, 2023

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.conf by 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.

@dber01
Copy link

dber01 commented Mar 27, 2023

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?

@notabotscott
Copy link

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.conf by 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

@B4n4n3
Copy link

B4n4n3 commented Mar 31, 2023

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.conf by 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.

@BobSmithPi
Copy link

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.

@bigOconstant
Copy link

None of these worked for me on a rpi4 running latest 64 bit os. Really wish I could use this new camera.

@m4rky-m4rk
Copy link

I have few cameras lying idle because of the issue and lack of time to dig into the issues.

@strips
Copy link

strips commented May 16, 2023

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.

@mgrn0
Copy link

mgrn0 commented May 16, 2023

@strips are you using this as a replacement for motioneye or 'just' (great idea :) ) as a streaming source / camera FOR motioneye?

@strips
Copy link

strips commented May 16, 2023

@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.

@bigOconstant
Copy link

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.

@strips
Copy link

strips commented May 16, 2023

@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.

@strips
Copy link

strips commented May 19, 2023

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

@github-0
Copy link

@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?

@D-an-W
Copy link

D-an-W commented Dec 3, 2023

He copied just my answer... You need to escape the slashes.

All working now, thank you!

@Peuz85
Copy link

Peuz85 commented Dec 3, 2023

He copied just my answer... You need to escape the slashes.

Du hast leider keine schritt für schritt anleitung geschrieben. Mit deiner "anleitung" so wie du sie geschrieben hast, ging leider gar nichts. Zudem kommt bei bookworm immer der fehler mit "... externally Environment" und dies muss man auch erst mal umgehen.
Danke für deine vorarbeit.

Lg und Grüsse aus Ö ;-)

@pingufreak
Copy link

pingufreak commented Dec 3, 2023 via email

@D-an-W
Copy link

D-an-W commented Dec 3, 2023

When using the Camera Module 3 and the working method above, what are the best camera and recording settings (Using a Zero 2 W currently) you have found?

@Stepyon
Copy link

Stepyon commented Dec 4, 2023

RaspiOs bookworm 64 bit with raspicam v3 (finally works)

sudo apt update && sudo apt upgrade -y

sudo rm -rf /usr/lib/python3.11/EXTERNALLY-MANAGED

sudo apt --no-install-recommends install ca-certificates curl python3 python3-distutils python3-dev libcurl4-openssl-dev gcc libssl-dev

curl -sSfO 'https://bootstrap.pypa.io/get-pip.py'

sudo python3 get-pip.py

sudo python3 -m pip install 'https://github.com/motioneye-project/motioneye/archive/dev.tar.gz'

sudo apt install -y libcamera-v4l2

sudo apt install -y libcamera-tools

sudo motioneye_init

sudo sed -i 's//usr/local/bin/meyectl//usr/bin/libcamerify /usr/local/bin/meyectl/' /etc/systemd/system/motioneye.service

sudo systemctl daemon-reload

sudo systemctl enable motioneye --now

sudo reboot

http://yourpiaddress:8765/

It can happen that when changes are made in the MotionEye, the message “unable to open video device” appears. sudo reboot (takes a little longer) and then it works

Have fun ;-)

This solution works except autofocus, is any way to make the autofocus working?

@axeljerabek
Copy link

There are also easier ways to get a module3 stream into motion or motionplus.
Just updated my old article and I have this setup running:
https://www.wetransco.de/debian-bookworm-and-libcamera-module-3/

@Stepyon
Copy link

Stepyon commented Dec 8, 2023

This solution works except autofocus, is any way to make the autofocus working?

I was able to control the focus manually from the camera window by adding the action buttons:
image

  1. Create a zoom_in_1 script file (where "1" is camera number) in /etc/motioneye/ folder:
    sudo nano /etc/motioneye/zoom_in_1
#!/bin/bash

# Define the device
device="/dev/v4l-subdev1"

# Define the maximum focus value
max_focus=960

# Get the current focus value
current_focus=$(v4l2-ctl -d $device --get-ctrl=focus_absolute | awk '{print $2}>

# Check if current focus is a number
if ! [[ $current_focus =~ ^[0-9]+$ ]] ; then
   echo "Error: Failed to get current focus value" >&2; exit 1
fi

# Increment the focus value by 20
new_focus=$((current_focus + 20))

# Check if the new focus exceeds the maximum
if [ $new_focus -gt $max_focus ]; then
    new_focus=$max_focus
fi

# Set the new focus value
v4l2-ctl -d $device -c focus_absolute=$new_focus

Create zoom_out_1 script in the same folder:
sudo nano /etc/motioneye/zoom_out_1

#!/bin/bash

# Define the device
device="/dev/v4l-subdev1"

# Define the minimum focus value
min_focus=320

# Get the current focus value
current_focus=$(v4l2-ctl -d $device --get-ctrl=focus_absolute | awk '{print $2}>

# Check if current focus is a number
if ! [[ $current_focus =~ ^[0-9]+$ ]] ; then
   echo "Error: Failed to get current focus value" >&2; exit 1
fi

# Decrease the focus value by 20
new_focus=$((current_focus - 20))

# Check if the new focus is below the minimum
if [ $new_focus -lt $min_focus ]; then
    new_focus=$min_focus
fi

# Set the new focus value
v4l2-ctl -d $device -c focus_absolute=$new_focus

Make them executable:
sudo chmod +x zoom_in_1
sudo chmod +x zoom_out_1

  1. Autofocus even when it is not working will reset the focus value every time you are trying to change it, to fix that you need to modify your camera json file which located here: /usr/share/libcamera/ipa/rpi/vc4 (in my case it is imx708_noir.json). Remove or just rename "rpi.af" section. See more details here

Now you should be able to control the camera focus manually straight from the camera window.

@haklan
Copy link

haklan commented Dec 18, 2023

@Peuz85 I installed motion on Bookworm according to your instruction and trying to setup a RPI HQ camera but I got "UNABLE TO OPEN VIDEODEVICE" in the stream. Reboot does not help. Got "VIDIOC_STREAMON: Invalid argument" in systemctl status. Do you have any ideas?

● motioneye.service - motionEye Server
Loaded: loaded (/etc/systemd/system/motioneye.service; enabled; preset: enabled)
Active: active (running) since Mon 2023-12-18 15:44:51 CET; 8min ago
Main PID: 561 (meyectl)
Tasks: 10 (limit: 765)
CPU: 10min 22.668s
CGroup: /system.slice/motioneye.service
├─561 /usr/bin/python3 /usr/local/bin/meyectl startserver -c /etc/motioneye/motioneye.conf
├─734 /usr/bin/python3 /usr/local/bin/meyectl startserver -c /etc/motioneye/motioneye.conf
└─765 /usr/bin/motion -n -c /etc/motioneye/motion.conf -d 5

Dec 18 15:52:40 birdcam motion[765]: [1:ml1:Camera1] [ERR] [VID] v4l2_mmap_set: Error starting stream. VIDIOC_STREAMON: Invalid argument
Dec 18 15:52:40 birdcam motion[765]: [1:ml1:Camera1] [ERR] [VID] vid_start: V4L2 device failed to open
Dec 18 15:52:50 birdcam motion[765]: [1:ml1:Camera1] [WRN] [ALL] mlp_retry: Retrying until successful connection with camera
Dec 18 15:52:50 birdcam motion[765]: [1:ml1:Camera1] [ERR] [VID] v4l2_fps_set: Error setting fps. Return code -1
Dec 18 15:52:50 birdcam motion[765]: [1:ml1:Camera1] [ERR] [VID] v4l2_mmap_set: Error starting stream. VIDIOC_STREAMON: Invalid argument
Dec 18 15:52:50 birdcam motion[765]: [1:ml1:Camera1] [ERR] [VID] vid_start: V4L2 device failed to open
Dec 18 15:53:00 birdcam motion[765]: [1:ml1:Camera1] [WRN] [ALL] mlp_retry: Retrying until successful connection with camera
Dec 18 15:53:00 birdcam motion[765]: [1:ml1:Camera1] [ERR] [VID] v4l2_fps_set: Error setting fps. Return code -1
Dec 18 15:53:00 birdcam motion[765]: [1:ml1:Camera1] [ERR] [VID] v4l2_mmap_set: Error starting stream. VIDIOC_STREAMON: Invalid argument
Dec 18 15:53:00 birdcam motion[765]: [1:ml1:Camera1] [ERR] [VID] vid_start: V4L2 device failed to open

@JustGlowing
Copy link

JustGlowing commented Jan 2, 2024

hello everyone, the instructions from @gpambrozio worked for me but I had to move motion.sh in /usr/bin and adjust the motioneye.conf accordingly. Hope this helps somebody :-)

Edit: While the camera worked, motion detection didn't as libcamerify/motion were going in segmentation fault. I downgraded to Buster and everything worked out of the box.

@Nuuki9
Copy link

Nuuki9 commented Jan 10, 2024

I previously tried Bookwork using instructions from @gpambrozio and had some success, but autofocus and changing settings didn't work, and I don't think motion detection did either.

Based on comments from @JustGlowing I've just tried Buster but I don't see any cameras listed at all when I select Local V4L2 Camera.

Clearly there are a lot of approaches being taken and all the work being put in is really appreciated. However with such a long thread and with differing methods its hard to nail down which ones work and with what caveats. Would it be feasible for us as a group to briefly write up any working methods in the wiki (or elsewhere), so we have a set of instructions that can be maintained and updated?

I bought the parts to make my mother a birdbox for her 80th, and so far its still on my workbench not working. As spring approaches I'd love to have this up and running for her.

@JustGlowing
Copy link

@Nuuki9 under buster the camera is listed under MMAL Camera, not V4L2 Camera.

@Nuuki9
Copy link

Nuuki9 commented Jan 10, 2024

@Nuuki9 under buster the camera is listed under MMAL Camera, not V4L2 Camera.

I'm pretty sure I checked that.

Currently Im testing the method @Peuz85 provided - that's actually working perfectly, expect the focus (as noted). I'll try adding the manual focus buttons and testing the motion capture, but hopefully it'll end up working.

@MichaIng
Copy link
Member

under buster the camera is listed under MMAL Camera, not V4L2 Camera

If you enable KMS (dtoverlay=vc4-kms-v3d), it is listed under V4L2. This is just the default since Bullseye. However, that way it is not working without libcamerify.

Lacking time to look into this right now: Does someone know whether this really is a motion issue, simply not supporting the new libcamera API, so that motionplus is required, or is there something else we can do our end to make it functional with motion without an API wrapper/emulator like libcamerify?

@strips
Copy link

strips commented Feb 4, 2024

@MichaIng This is the only reference to libcamera in Motion I can find: https://motion-project.github.io/motion_config.html

The raspberry Pi camera is set up via an application called libcamera. libcamera provides access to the camera as a v4l2 device but this interface is only available when using a special application. Users must run Motion using the command libcamerify motion and then specify the /dev/videoX device in the Motion configuration file.

I believe I read somewhere that Motion will not get native support for libcamera. MotionPlus is the way to go forward. I'm using only MotionPlus now where I was using Motion with MotionEye before. Works pretty good after lots of fiddling with the config files. I miss the ease of MotionEye.

To create the confusion absolute the RPI-guys have renamed libcam to rpicam: https://www.raspberrypi.com/documentation/computers/camera_software.html

rpicam-apps applications have been renamed from libcamera-* to rpicam-*. Symbolic links are installed to allow users to keep using the old application names, but these will be deprecated in the future. Users are encouraged to adopt the new application names as soon as possible.

@axeljerabek
Copy link

At the moment, I run motionplus and am quite happy with it. Still, from the Raspberries, I feed the stream directly from the libcamera-apps (or the newer version) into the rtmp module from nginx and feed motion(plus) with this stream as netcam. Makes the softwares a bit more independend and I can actually create the stream on the Raspberry directly as h264 stream and motion records without reencoding, that saves a lot of power on the Raspberry side, so that I even have a few small Raspberry Zeros as camera platforms, since the motion software runs on an Intel Nuc11 which has a lot more power and can pickup the streams of 6 cameras. As said, not to be reencoded, that is one big advantage, and also the Raspberries are not overcomputing any motion parts. Still you are free where you run your motion software, can also be on a Raspberry. My setup is partly documented here:
https://www.wetransco.de/2023/12/raspberry-pi-zero-2w-debian-bookworm-und-libcamera-module-2-3-streaming/

@mishramahim
Copy link

mishramahim commented Feb 10, 2024

RaspiOs bookworm 64 bit with raspicam v3 (finally works)

sudo apt update && sudo apt upgrade -y

sudo rm -rf /usr/lib/python3.11/EXTERNALLY-MANAGED

sudo apt --no-install-recommends install ca-certificates curl python3 python3-distutils python3-dev libcurl4-openssl-dev gcc libssl-dev

curl -sSfO 'https://bootstrap.pypa.io/get-pip.py'

sudo python3 get-pip.py

sudo python3 -m pip install 'https://github.com/motioneye-project/motioneye/archive/dev.tar.gz'

sudo apt install -y libcamera-v4l2

sudo apt install -y libcamera-tools

sudo motioneye_init

sudo sed -i 's//usr/local/bin/meyectl//usr/bin/libcamerify /usr/local/bin/meyectl/' /etc/systemd/system/motioneye.service

sudo systemctl daemon-reload

sudo systemctl enable motioneye --now

sudo reboot

http://yourpiaddress:8765/
It can happen that when changes are made in the MotionEye, the message “unable to open video device” appears. sudo reboot (takes a little longer) and then it works
Have fun ;-)

This solution works except autofocus, is any way to make the autofocus working?


Hi I tried this process MotioneyeOS is working under camera showing unicam using /dev/video0 but it is still showing “unable to open video device”

using aarch64
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debia

libcamera-hello is giving msg
Unable to set format: Device or resource busy
v4l2-ctl --list-devices
unicam (platform:3f801000.csi):
/dev/video0
/dev/video1
/dev/media3

sudo v4l2-ctl --device=/dev/video1 --all
Driver Info:
Driver name : unicam
Card type : unicam
Bus info : platform:3f801000.csi
Driver version : 6.1.73
Capabilities : 0xa5a00001
Video Capture
Metadata Capture
Read/Write
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x25a00000
Metadata Capture
Read/Write
Streaming
Extended Pix Format
Media Driver Info:
Driver name : unicam
Model : unicam
Serial :
Bus info : platform:3f801000.csi
Media version : 6.1.73
Hardware revision: 0x00000000 (0)
Driver version : 6.1.73

Need support struggling on this from long time. Not and expert but love to work with PI

@mishramahim
Copy link

Tried this command
sudo sed -i 's//usr/local/bin/meyectl//usr/bin/libcamerify /usr/local/bin/meyectl/' /etc/systemd/system/motioneye.service

getting msg
sed: -e expression #1, char 8: unknown option to `s'

@pingufreak
Copy link

pingufreak commented Feb 10, 2024 via email

@mishramahim
Copy link

mishramahim commented Feb 15, 2024

It was working with the solution shared but camera stop working after 5 to 6hrs of operation and it start showing issues. Raspberry Pi 2 W Zero was heating up I shifted to 4B with good heatsink but is is still working 5 to 6 hours.
Any other method of using camera module 3 with bookwork Raspberry pi 4B

@mishramahim
Copy link

Hi can anyone help My camera is getting detected but not working. I used other camera(RPI 1.3) with same cable and same is working fine.
Screenshot 2024-02-19 014110
Screenshot

@MichaIng
Copy link
Member

Btw, an alternative to libcamerify is to create a local network stream via rpicam-vid (previously raspivid) and attach that as network camera to motionEye: https://www.raspberrypi.com/documentation/computers/camera_software.html#network-streaming
But not sure about performance implications.

@raspberrypicoder1
Copy link

I've just read through this, and am really confused. Can anyone give a step-by-step tutorial for Raspberry Pi OS 64bit, on a raspberry pi 4? I am using the camera module 3.

@MichaIng
Copy link
Member

MichaIng commented Jul 4, 2024

@raspberrypicoder1
After following the motionEye install instructions: https://github.com/motioneye-project/motioneye?tab=readme-ov-file#installation

apt install libcamera-v4l2 libcamera-tools
sed -i 's|^ExecStart=/usr/local/bin/meyectl|ExecStart=/usr/bin/libcamerify /usr/local/bin/meyectl|' /etc/systemd/system/motioneye.service
systemctl daemon-reload
systemctl restart motioneye

@letkan
Copy link

letkan commented Jul 4, 2024

apt install libcamera-v4l2 libcamera-tools
sed -i 's|^ExecStart=/usr/local/bin/meyectl|ExecStart=/usr/bin/libcamerify /usr/local/bin/meyectl|' /etc/systemd/system/motioneye.service
systemctl daemon-reload
systemctl restart motioneye

Hi, it took me a while to find these commands but now my camera 3 works with motioneye, thanks.
The next thing to figure out is how to enable autofocus in this context (not being a programmer).
Any help would be appreciated.

@MichaIng
Copy link
Member

MichaIng commented Jul 4, 2024

It is not enabled by default?

This guide seems complete: https://www.tomshardware.com/how-to/raspberry-pi-camera-module-3-python-picamera-2
Not sure whether this is in scope for motionEye. Probably if someone is just in mood and has the time to implement a nice GUI to toggle it, using this or another picamera Python module. On my end, I'll implement libcamerify first, so that it is offered to be installed automatically, when libcamera API is detected on Raspberry Pi, and probably calling the internal motion instances with libcamerify, instead of the whole meyectl process. But not sure yet which one is better, performance-wise of for other reasons. The benefit of wrapping meyectl itself is, that the RPi camera module appears as regular V4L2 camera 🤔.

@letkan
Copy link

letkan commented Jul 9, 2024

As per my test, autofocus is not implemented by default. The guide you mention is complete but the requirements are both libcamera and picamera2 and I haven't seen a way to use them with Motioneye.

from picamera2 import Picamera2
from libcamera import controls
picam2 = Picamera2()
picam2.start(show_preview=True)
picam2.set_controls({"AfMode": controls.AfModeEnum.Continuous})

Meanwhile I switched to Motionplus which plays much nicer with this camera and allows option for continuous autofocus and all. To me it looks like the way forward is libcamera instead of v4l2. I don't like loosing the nice web interface of Motioneye to config files but overall, the final setup works better in my case. Motionplus has a web interface also but it is rudimentary by comparison.

@shooftie
Copy link

shooftie commented Jul 9, 2024

RPi 3 Model A+ (aarch64) – DietPi v9.6.1 – RPi Camera Module v3 Noir

I tried everything in this thread and the only thing that worked for me was:

  • install dev branch (I did this via dietpi-software)
  • apt install libcamera-v4l2 libcamera-tools
  • sed -i 's/\/usr\/local\/bin\/meyectl/\/usr\/bin\/libcamerify \/usr\/local\/bin\/meyectl/' /etc/systemd/system/motioneye.service

This was the key for me.

Pretty sure that this was a fresh install of Diet-Pi, too. I will give it another flash and report back if otherwise.

@letkan
Copy link

letkan commented Jul 9, 2024

I'm on the same OS/version, are you saying with the above settings (which I've also used) you got autofocus working without any other config settings, "out-of-the-box", so to speak?
For libcamera:autofocus there are 3 states:

  • manual
  • auto (whatever that means)
  • continuous

which need to be set either by code i.e.
picam2.set_controls({"AfMode": controls.AfModeEnum.Continuous})
or in a .conf file as in Motionplus. That's what I've learned so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests