Add libcamera (CSI/picam) cam support on the Pi5 (spyglass)
LadPack opened this issue · 20 comments
What happened
When attempting to add in a ov5647 camera on mainsail, there is consistently a no-signal when adding via the mainsail UI. Tested the camera module via CLI and was able to receive pictures.
What did you expect to happen
Normally when I have done this in the past (including with this camera module on a Pi4) it would pick up the picam with no intervention on my end.
How to reproduce
Fresh Pi5 install, via KIAUH, plug in camera.
Additional information
[02/08/24 19:18:27] crowsnest: crowsnest - A webcam Service for multiple Cams and Stream Services.
[02/08/24 19:18:27] crowsnest: Version: v4.1.3-1-gc0c9c41
[02/08/24 19:18:27] crowsnest: Prepare Startup ...
[02/08/24 19:18:27] crowsnest: INFO: Host information:
[02/08/24 19:18:27] crowsnest: Host Info: Distribution: Debian GNU/Linux 12 (bookworm)
[02/08/24 19:18:27] crowsnest: Host Info: Kernel: Linux 6.1.0-rpi7-rpi-2712 aarch64
[02/08/24 19:18:27] crowsnest: Host Info: Model: Raspberry Pi 5 Model B Rev 1.0
[02/08/24 19:18:27] crowsnest: Host Info: Available CPU Cores: 4
[02/08/24 19:18:27] crowsnest: Host Info: Available Memory: 4143600 kB
[02/08/24 19:18:27] crowsnest: Host Info: Diskspace (avail. / total): 18G / 29G
[02/08/24 19:18:27] crowsnest: INFO: Checking Dependencies
[02/08/24 19:18:27] crowsnest: Dependency: 'crudini' found in /usr/bin/crudini.
[02/08/24 19:18:27] crowsnest: Dependency: 'find' found in /usr/bin/find.
[02/08/24 19:18:27] crowsnest: Dependency: 'xargs' found in /usr/bin/xargs.
[02/08/24 19:18:27] crowsnest: Dependency: 'ustreamer' found in bin/ustreamer/ustreamer.
[02/08/24 19:18:27] crowsnest: Version Control: ustreamer new version available: b578e98 (v5.49).
[02/08/24 19:18:27] crowsnest: INFO: Print Configfile: '/home/david/printer_data/config/crowsnest.conf'
[02/08/24 19:18:27] crowsnest: [crowsnest]
[02/08/24 19:18:27] crowsnest: log_path: /home/david/printer_data/logs/crowsnest.log
[02/08/24 19:18:27] crowsnest: log_level: verbose
[02/08/24 19:18:27] crowsnest: delete_log: true
[02/08/24 19:18:27] crowsnest: no_proxy: false
[02/08/24 19:18:27] crowsnest:
[02/08/24 19:18:27] crowsnest: [cam 1]
[02/08/24 19:18:27] crowsnest: mode: ustreamer
[02/08/24 19:18:27] crowsnest:
[02/08/24 19:18:27] crowsnest: enable_rtsp: false
[02/08/24 19:18:27] crowsnest: rtsp_port: 8554
[02/08/24 19:18:27] crowsnest: port: 8080
[02/08/24 19:18:27] crowsnest: device: /dev/video0
[02/08/24 19:18:27] crowsnest: resolution: 640x480
[02/08/24 19:18:27] crowsnest: max_fps: 15
[02/08/24 19:18:27] crowsnest: INFO: Detect available Devices
[02/08/24 19:18:27] crowsnest: INFO: Found 1 total available Device(s)
[02/08/24 19:18:27] crowsnest: ================================================================
[02/08/24 19:18:27] crowsnest: WARN: 'libcamera' devices are currently not supported on Pi 5!
[02/08/24 19:18:27] crowsnest: ================================================================
[02/08/24 19:18:27] crowsnest: Detected 'libcamera' device -> /base/axi/pcie@120000/rp1/i2c@80000/ov5647@36
[02/08/24 19:18:27] crowsnest: Try to start configured Cams / Services...
[02/08/24 19:18:27] crowsnest: INFO: Configuration of Section [cam 1] looks good. Continue ...
[02/08/24 19:18:28] crowsnest: V4L2 Control: No parameters set for [cam 1]. Skipped.
[02/08/24 19:18:28] crowsnest: Starting ustreamer with Device /dev/video0 ...
[02/08/24 19:18:30] crowsnest: ... Done!
Tested the camera module via CLI and was able to receive pictures.
Please elaborate further on this. What exact command did you run? This won't change anything below, I'm just curious.
As you can read on your log snippet, we don't support libcamera devices on the Pi5. Therefore no CSI cam support atm.
If you used the legacy stack to get an image, you have to know that we cannot make it work consistently with the legacy stack on Bookworm. Also that legacy stack will be removed in future versions of Raspberry Pi OS, so it shouldn't be used.
We will add some support in the future but for now we cannot support it.
I changed it to a feature request, as we currently don't support it as clearly stated in the log.
I used libcamera-hello to get a picture file.
Ah got it, so any and all of the pi cameras are no longer supported as of the pi5? Is that more of a Pi5 thing or just because it is new? Is there a workaround potentially to have the pi serve up some sort of ip camera to look at?
I tried camera-streamer which didn't work either for this purpose.
It's an overall Pi5 issue atm. We are using camera-streamer as our backend. As that doesn't work with the Pi5, we don't support it.
The problem with the Pi5 is the missing JPEG, MJPG and H264 hardware encoders, that's why camera-streamer doesn't support it.
Some kind of workaround/alternative would be spyglass with some adjustments. I might go into detail about it later today. Basically you need to change one of the includes that it's using the software encoder instead of the hardware encoder.
We will add spyglass in an upcoming update, but, like I wrote earlier, that's currently not possible for us.
So interim, if I have the option to use a pi4, then its probably better to use it? Just for ease of use
Exactly a Pi4 would work as expected. It's really just the Pi5 with it's hardware limitations (sounds wrong as it's the newer device but it's actually like that).
To the Spyglass workaround:
Only use this for picams/CSI cams on a Pi5! This doesn't have WebRTC support!
You need to install some packages for spyglass to work.
sudo apt update
sudo apt install python3-libcamera python3-kms++ python3-picamera2
Then clone the repository and follow the instructions on how to install as a service.
To get the best performance, you should change line 11 inside ~/spyglass/spyglass/cli.py
from
from picamera2.encoders import MJPEGEncoder
to
from picamera2.encoders import JpegEncoder as MJPEGEncoder
Make sure to comment out the picam/csi cam in crowsnest or stop/disable crowsnest completely.
You should also adjust the spyglass.conf
(found at the same place as the crowsnest.conf) to the correct streaming and snapshot url.
Like written above someone should only use this for picams/CSI cams. Spyglass only supports one cam at the same time.
I won't give support on this workaround in this issue or in this repository. If you need some help, join our Discord or use the spyglass issue tracker. This should only be treated as a workaround and not as a final solution.