crowsnest icon indicating copy to clipboard operation
crowsnest copied to clipboard

Add libcamera (CSI/picam) cam support on the Pi5 (spyglass)

Open LadPack opened this issue 1 year ago • 18 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!

LadPack avatar Feb 09 '24 00:02 LadPack

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.

mryel00 avatar Feb 09 '24 12:02 mryel00

I changed it to a feature request, as we currently don't support it as clearly stated in the log.

mryel00 avatar Feb 09 '24 12:02 mryel00

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.

LadPack avatar Feb 09 '24 12:02 LadPack

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.

mryel00 avatar Feb 09 '24 12:02 mryel00

So interim, if I have the option to use a pi4, then its probably better to use it? Just for ease of use

LadPack avatar Feb 09 '24 16:02 LadPack

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.

We do not recommend to use a Pi5!

mryel00 avatar Feb 09 '24 22:02 mryel00

This is a +1 from me with the same issue now.

I only have a pi5 available which is why I'm trying to use it. Would this feature request more accurately be described as using an H.265 codec method for streaming for Pi5's?

FYI Spyglass isn't a workaround for me, as last time I tried it, this wouldn't stream to Obico which is the main reason I use a webcam.

My logs are the same...

LOGS

[07/02/24 23:06:25] crowsnest: INFO: Found 1 total available Device(s) [07/02/24 23:06:25] crowsnest: ================================================================ [07/02/24 23:06:25] crowsnest: WARN: 'libcamera' devices are currently not supported on Pi 5! [07/02/24 23:06:25] crowsnest: ================================================================ [07/02/24 23:06:25] crowsnest: Detected 'libcamera' device -> /base/axi/pcie@120000/rp1/i2c@88000/imx519@1a [07/02/24 23:06:25] crowsnest: Try to start configured Cams / Services... [07/02/24 23:06:26] crowsnest: INFO: Configuration of Section [cam 1] looks good. Continue ... [07/02/24 23:06:26] crowsnest: WARN: Mode 'camera-streamer' is not supported on your device! [07/02/24 23:06:26] crowsnest: WARN: Falling back to Mode 'ustreamer' [07/02/24 23:06:26] crowsnest: V4L2 Control: No parameters set for [cam 1]. Skipped. [07/02/24 23:06:26] crowsnest: Starting ustreamer with Device /base/axi/pcie@120000/rp1/i2c@88000/imx519@1a ... [07/02/24 23:06:28] crowsnest: ... Done! [07/02/24 23:06:28] crowsnest: WATCHDOG: Lost Device: '/base/axi/pcie@120000/rp1/i2c@88000/imx519@1a'

chalb0 avatar Jul 02 '24 22:07 chalb0

If you read the log, you would understand, why you have the same problem. It's still not supported.

There is no reason why Spyglass shouldn't work with Obico. Crowsnest (ustreamer/camera-streamer) do nothing special compared to Spyglass. (I already wrote, how to get help for Spyglass but it's more like a Obico topic)

Would this feature request more accurately be described as using an H.265 codec method for streaming for Pi5's?

There is no intention from us to use H265 encoding, and we are not aware of any backend that is able to do this easily with the Pi5 encoder, but we didn't really search for it. H265 isn't available in some browsers by default, therefore that's no solution we will consider atm.

Our solution will be Spyglass, as we will add it with the next big version update, that has no current ETA, for multiple reasons.

mryel00 avatar Jul 03 '24 06:07 mryel00

There is no intention from us to use H265 encoding, and we are not aware of any backend that is able to do this easily with the Pi5 encoder, but we didn't really search for it.

Wow, so helpful... Glad I switched to something other than Crowsnest since Mainsail devs are lightning fast at development and sooooo helpful /s

Why even have a feature request tag if you don't have any intentions of adding features people want?

rykerg9 avatar Jul 06 '24 21:07 rykerg9

Glad I switched to something other than Crowsnest

Good that you found something that already supports H265 encoding and that works for you, but the rest of your message is just intentionally upsetting right? Please read everything, if you want to understand the background of this whole thing.

Why even have a feature request tag if you don't have any intentions of adding features people want?

You didn't read all the messages, did you? You just picked one thing out of this whole thread. The FR is support for pi cams on the Pi5. The current workaround that I shared, will be the future implementation, but there are other things that have to be done first. There is only no intention for H265 support (See the last paragraph). If you got a backend that supports it, you can share it if you want, and I can take a look at it. Otherwise there will be only Spyglass with MJPG and WebRTC (only H264 planned atm) support. Spyglass doesn't have WebRTC support atm, that's one of the reasons, why this FR still take some time.

Mainsail devs are lightning fast at development

The Mainsail Crew is just some loosely group of people that are helping meteyou with development of different projects around Mainsail for the Klipper project. Mete, and we others, don't get money and do this in our free time. It's sad to see that people think we are obligated to get everything done, as fast as some company, with multiple devs behind each project, even if we are mostly one dev for one project. We are happy if people like our work, but sometimes messages like yours are really getting on someone nerves. You don't have to like our work, but you also don't have to complain about it, especially if you found a better alternative for yourself, and don't even want to share it with others. Crowsnest is pretty slow developing, but that's due to the time constraints I and other people have. Also this is open source, so just make a fork if someone is too slow for you.

sooooo helpful

When were we not helpful? We give support on different plattforms (one of the things consuming my time, so you can help out, if I should invest more time into Crowsnest 😉). I even provided a workaround that I can personally support, instead of sharing other peoples projects and sending all the support to them, and therefore "stealing" their time.

(The following paragraph might be wrong at some points, have a look at the edit below it) Are we not helpful, because I wrote, that we won't add H265? Why did I choose to not search for some H265 backend? You should maybe investigate, if your browser even got support activated, with a site like this. For me on the latest Chrome version on Windows (I guess this is one of the most common setups), it isn't activated. So I think, you didn't know what H265 is, while you wrote that message. I won't support a thing, just for the sake of supporting it and then creating even more support posts from people that are already overwhelmed with this project (most prominent problem is activating a picam....)

edit: Seems like I might have been a bit misinformed, and it's supported for quite some time. That page is not nearly an indicator for the things that are supported, as those tests seem to be for native HTML5 only(?). So we will look into it ofc. edit2: Also it's only a HW decoder and not an encoder

mryel00 avatar Jul 07 '24 09:07 mryel00

I edited now the title, that people understand what's the feature behind this FR

mryel00 avatar Jul 07 '24 09:07 mryel00

@rykerg9 this is all open source. feel free to fork this project or start your own project, develop, maintain and support it all in your free time without get paid for anything and then let other people insult you for doing something free for everyone.

so this is all free... just use it, or let it... but pls don't be a dick...

meteyou avatar Jul 07 '24 13:07 meteyou

@meteyou

but pls don't be a dick...

Never expected name calling as well, wow. Very professional. slow clap

also @mryel00 I'm not reading the literal book that you replied with since I have better things to do than get pinged and bothered by the people here, like actually printing things and not getting butt hurt that someone called you out on your piss poor "support".

Thanks anyways though <3

rykerg9 avatar Jul 07 '24 14:07 rykerg9

@rykerg9 Then a short version of that book: We will add Pi5 support, but won't add H265 specifically, as it isn't supported by default in most browsers. Also please share your alternative for other people, that your comment wasn't just a complaint, but something useful for this discussion.

mryel00 avatar Jul 07 '24 14:07 mryel00

Just to clarify, my “+1” was to confirm I knew I encountered the same issue and wanted to understand a little more about the situation to decide if I source a pi4, or continue to invest time with spyglass or wait, exactly what you have given me @mryel00, thank you.

As it turns out, I’ve managed to get spyglass working and using Obico with a little more effort (I could already get it streaming fine to mainsail) I have done this with a 32bit OS as I’ve found comments that 64bit didn’t work (which I too have yet to get working).

For anyone else interested… my setup is (what I had available from other projects): Arducam 16MP AF (IMX519). Raspberry Pi5. Raspberry Pi OS 32bit Bookworm Spyglass (not installed crowsnest on a new setup).

Clean install of OS 32bit Setup Klipper and others with KIAUH. Followed install setups for Arducam on their wiki. Followed setup guide for spyglass with Obico on Spyglass GitHub (there’s a few steps not recorded to do with using the right path on the Obico config).

chalb0 avatar Jul 07 '24 15:07 chalb0

setup guide for spyglass with Obico on Spyglass GitHub

Can you link me what you mean with that guide? edit: nvm found it: https://github.com/roamingthings/spyglass/discussions/38 (I completely forgot about the discussions xD)

mryel00 avatar Jul 07 '24 15:07 mryel00

More detailed workaround steps. I've NOW got it working on x64 with Spyglass and Obico.

Install the Camera

Install Klipper, Moonraker, Mainsail, Obico for Moonraker via KUAIH: https://github.com/dw-0/kiauh Link Obico to your account as part of this step.

Install the Camera

Using whichever camera guide you have. My Arducam 16mp AF was here: https://docs.arducam.com/Raspberry-Pi-Camera/Native-camera/16MP-IMX519/ Make sure you set the right interface you're using (CAM0 needed to be explicitly listed in /boot/firmware/config.txt for me).

Spyglass setup guide:

https://github.com/roamingthings/spyglass CLI on Pi5:

cd ~
git clone https://github.com/roamingthings/spyglass
cd ~/spyglass
make install

Modify spyglass.conf

This can be to your preferences, or may need to set specific Resolution compatible with your camera.

Setup the Webcam in Mainsail UI

URL Steam: /webcam/stream URL Snapshot: /webcam/snapshot Service: UV4L-MJPEG At this point, you should be able to see the webcam in your UI. If not, revisit camera setup.

Install Janus

This doesn't seem to be included in Spyglass and is needed for Obico to stream. CLI on Pi5:

sudo apt install janus

Modify moonraker-obico.cfg

under the webcam section make sure these two entries are there. moonraker-obico.cgf:

[webcam]
stream_url = "http://127.0.0.1:8080/stream"
snapshot_url = "http://127.0.0.1:8080/snapshot"

Troubleshooting:

  1. Check Obico Notifications (via web interface https://app.obico.io/printer_events/ )
  2. Check the moonraker obico logs cat /home/pi/printer_data/logs/moonraker-obico.log (note change "pi" for your username)

chalb0 avatar Jul 07 '24 22:07 chalb0

I read again my previous longer explanation and wanted to clarify it as a separate comment, might be interesting for @rykerg9 too: The Pi5 has no HW video encoding. It's only a H265 HW decoder. It seems like some people get good results with specific settings of ffmpeg that I don't know of. But I also don't know the quality of the image output, I just heard about some good results. So any information on that will be helpful if someone also wants WebRTC without high CPU usage on the Pi5.

Also I added WebRTC to Spyglass, but it's still experimental, as I have to do some testing on it. The CPU usage on the Pi5 is quite high and therefore it shouldn't be used with it, or at least only with caution: https://github.com/mryel00/spyglass/pull/84

mryel00 avatar Aug 23 '24 16:08 mryel00