Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5782

Camera board • Re: Using Camera Module 3 in browser

$
0
0
I'm using the camera 2 module, but my workaround (for chromium, it does not work with firefox) should work for the module 3 too. Might need to change resolution and pixelformat if module 3 can't output YUY2, but I cannot confirm this until I get the latest camera myself. Basically I use gstreamer to pipe raw camera output to virtual camera device on v4l2loopback, it introduces a small overhead of course and chromium doesn't have access to camera controls which you need to manipulate via the pipeline, but otherwise this works really well for me.
I have tested this method with fresh install on Raspberry Pi 4, with camera module 2 and Raspberry Pi OS 64-bit 10 Oct. release:

Steps for my workaround:

install gstreamer and necessary plugins:

Code:

sudo apt-get install -y gstreamer1.0-tools gstreamer1.0-plugins gstreamer1.0-libcamera
Install the loopback (this can fail if you upgraded the kernel because of headers mismatch)

Code:

sudo apt-get install -y v4l2loopback-dkms
Activate the loopback module on startup:

Code:

sudo nano /etc/modules-load.d/v4l2loopback.conf
paste this into the file and save:

Code:

v4l2loopback
Configure the virtual camera device:

Code:

sudo nano /etc/modprobe.d/v4l2loopback.conf
and paste the following content inside:

Code:

options v4l2loopback video_nr=8options v4l2loopback card_label="Chromium device"options v4l2loopback exclusive_caps=1
Make sure the video_nr= doesn't collide with any video devices already present, check this with

Code:

ls /dev/
If there's video8 already present, pick another number.
Now reboot and start gstreamer pipeline:

Code:

gst-launch-1.0 libcamerasrc ! "video/x-raw,width=1280,height=1080,format=YUY2",interlace-mode=progressive ! videoconvert ! v4l2sink device=/dev/video8
This command needs to be running when you use the camera with the browser , either do it manually or set it to boot with the system by crontab or any other method.

Afterwards chromium should see this as a normal camera it can access, I use https://webrtc.github.io/samples/src/co ... esolution/ to verify. Gstreamer will complain about lack of queues, but I didn't notice any hiccups in the stream and it crashes after I add them.

If this pipeline fails, there's a safer one that should be more universal if module 3 cannot run with the same settings:

Code:

gst-launch-1.0 libcamerasrc ! "video/x-raw,width=1280,height=1080" ! videoconvert ! v4l2sink device=/dev/video8
It puts more CPU strain on the videoconvert element as it will also have to handle pixel format conversion on the fly, but it should still be manageable.

You can of course set a higher resolution, 1280x1080 is just the one I use.
This is cracking - thanks a lot! Works great with Module 3 on Bookworm.

Statistics: Posted by czarop — Wed Jan 24, 2024 7:25 pm



Viewing all articles
Browse latest Browse all 5782

Trending Articles