CameraBin error: allocation failed - possible solution / workaround

Hi all,
So a bit of background. I’m running LightBurn on Linux Mint 21.1 (Ubuntu 21.1 based). I had a camera that was working OK, but had a lens that was too narrow. I picked up another with a wider lens that happened to be a higher resolution - 16MP vs 4MP I believe. Very similar to the original one otherwise, but I started to get the “allocation failed” error. I found an earlier thread on here (https://forum.lightburnsoftware.com/t/ubuntu-linux-camerabin-error-allocation-failed/94067) that is now closed but the suspicion there was a mismatch in some library versions.

That didn’t quite track for me, as the old camera and new one both use the same driver. So I started to suspect that the real cause at least for me was the increased resolution. Allocation usually refers to memory allocation, and I figured the memory allocation required for the image buffers for the new camera was probably 4x the old one at least. But LightBurn defaults to the max resolution (and switching between “Default” and “Max Resolution” in settings made no difference) and I couldn’t find a way to override that.

Finally I found this on another forum. Basically it involves creating a virtual camera with only a single resolution and feeding the real camera thru that, then using the virtual camera in LightBurn. I created a little shell script with this:

#! /bin/bash

# Create a virtual camera at /dev/video7 named VirtualCam
sudo modprobe v4l2loopback devices=1 video_nr=7 card_label="VirtualCam" exclusive_caps=1

# Forward video from /dev/video0 to /dev/video7 at the given resolution
ffmpeg -f video4linux2 -framerate 30 -video_size 1600x1200 -input_format mjpeg -i /dev/video0 -f v4l2 -pix_fmt yuv420p /dev/video7

You may need to edit to select a different resolution and/or video device depending on your setup.

I know I had to install ffmpeg (sudo apt install ffmpeg) but I’m not sure if v4l2loopback was already installed or if it got installed with the v4l2 utilities I installed earlier.

Run the script in a terminal and it will keep running outputting some statistics. Start LightBurn and if everything is right, select “VirtualCam” as your camera.

It would be really great if LightBurn could add a dropdown or something to allow selecting a specific resolution rather than just “Default” and “Max”.

Hope this helps if you’re having this problem!

Eddie

1 Like

Quick followup - while this works, after messing with it a bit more it’s kind of unstable. The ffmpeg utility will somethings just crash and stop working and then won’t start again until the computer is restarted. It doesn’t cause any other problem that I’ve seen - LightBurn will continue to run fine, just the camera goes away. I’ll keep experimenting.

1 Like

A few more data points from more testing. I think it’s sensitive to the order I start things up, and it may be related to having my laser (Atezr P20) and the camera going thru a hub in my enclosure rather than both connected directly to the PC. It seems to cause a problem if I run the script BEFORE turning on the laser. Making sure the laser is on first seems to keep it from happening.

I also found I can recover without rebooting by removing the loopback module after it crashes. I modified my script to just always do that before loading the module:

#! /bin/bash

# Remove the loopback module to make sure we're starting clean
sudo modprobe -r v4l2loopback

# Create a virtual camera at /dev/video7 named VirtualCam
sudo modprobe v4l2loopback devices=1 video_nr=7 card_label="VirtualCam" exclusive_caps=1

# Forward video from /dev/video0 to /dev/video7 at the given resolution
ffmpeg -f video4linux2 -framerate 30 -video_size 1600x1200 -input_format mjpeg -i /dev/video0 -f v4l2 -pix_fmt yuv420p /dev/video7

Hey, great tip. I have been trying to do the same for days now but still no succeed. gstreamer didn’t work at all. then I come across your script and able to create virtual cam from actual webcam. Lightburn also recognizes it but for some reason I keep getting blank screen. Lens calibration also same, Next button never gets enabled with 3 cameras I have. Even tried an IP camera. If I switch to Wayland, it just crashes to desktop. Did you ever come across this issue on your system?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.