Libcamera, IMX519, Octopi stream interruptions

Hello I have successfully set up Arducam 16MP AutoFocus on my OctoPi.
Using Raspbian Bullseye image and libcamera-dev + libcamera-apps 0.0.7 (because mjpg-streamer-experimental won’t compile with versions 0.0.8 and 0.0.9).
I got image and video stream, but the stream is being interrupted every 2-3 minutes. Basically the video stream “stops”. I can fix it for a next few minutes by reloading web browser (or Cura slicer window or mobile application) but after the next 2-3 minutes, video stops again.

Any ideas how to fix this? It is very annoying.

@Boos

Sorry, we didn’t update at the same time, we will update later.

This is a strange phenomenon and we will test it.

@Edward I managed to fix my problem. I did a clean install with libcamera 0.0.9. Camera worked perfectly until I added some plugins. I manage to round it down to OctoApp integration. But it’s kind of not their fault I think.
Problem is that when taking snapshots, camera mode switches to another resolution and then back to my configured stream resolution. When plugin do this “rapidly” like every few seconds, webcamd crashes. Also FPS is kind of weird, with -f 10, the stream is much smoother than with -f 30 or -f 15.

Starting up webcamDaemon...

--- Configuration: ----------------------------
cfg_file:      /boot/octopi.txt
camera:        libcamera
usb options:   -r 640x480 -f 10
raspi options: -fps 10
libcamera options: -r 1920x1080 -f 10
http options:  -w ./www -n

Explicitly set USB device:
-----------------------------------------------

Found video devices:
/dev/video0
/dev/video1
/dev/video10
/dev/video11
/dev/video12
/dev/video13
/dev/video14
/dev/video15
/dev/video16
/dev/video18
/dev/video19
/dev/video20
/dev/video21
/dev/video22
/dev/video23
/dev/video31
config file='/boot/octopi.txt':Starting MJPG-streamer with video device: libcamera
<13>Oct  8 19:51:38 root: Starting Libcamera camera
Checking for VL805 (Raspberry Pi 4)...
  - It seems that you don't have VL805 (Raspberry Pi 4).
    There should be no problems with USB (a.k.a. select() timeout)
Running ./mjpg_streamer -o output_http.so -w ./www -n -i input_libcamera.so -r 1920x1080 -f 10
MJPG Streamer Version: git rev: a6c7b4abbcd4887ed65f5e2c7bdecc065d8df7c6
 i: Desired Resolution: 1920 x 1080
[1:00:45.770465993] [4276]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3896-6019b245
[1:00:45.833700448] [4278]  WARN CameraSensorProperties camera_sensor_properties.cpp:174 No static properties available for 'imx519'
[1:00:45.833783225] [4278]  WARN CameraSensorProperties camera_sensor_properties.cpp:176 Please consider updating the camera sensor properties database
[1:00:45.848667323] [4278]  WARN RPI raspberrypi.cpp:1280 Mismatch between Unicam and CamHelper for embedded data usage!
[1:00:45.850151416] [4278] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/v4l-subdev0
[1:00:45.850443690] [4278]  INFO RPI raspberrypi.cpp:1404 Registered camera /base/soc/i2c0mux/[email protected]/[email protected] to Unicam device /dev/media4 and ISP device /dev/media0
 o: www-folder-path......: ./www/
 o: HTTP TCP port........: 8080
 o: HTTP Listen Address..: (null)
 o: username:password....: disabled
 o: commands.............: disabled
[1:00:45.852119707] [4281]  INFO Camera camera.cpp:1035 configuring streams: (0) 1920x1080-BGR888
[1:00:45.852720977] [4278]  INFO RPI raspberrypi.cpp:765 Sensor: /base/soc/i2c0mux/[email protected]/[email protected] - Selected sensor format: 1920x1080-SRGGB10_1X10 - Selected unicam format: 1920x1080-pRAA
[1:00:46.066454607] [4281]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3896-6019b245
[1:00:46.171936494] [4285]  WARN CameraSensorProperties camera_sensor_properties.cpp:174 No static properties available for 'imx519'
[1:00:46.172014771] [4285]  WARN CameraSensorProperties camera_sensor_properties.cpp:176 Please consider updating the camera sensor properties database
[1:00:46.184578748] [4285]  WARN RPI raspberrypi.cpp:1280 Mismatch between Unicam and CamHelper for embedded data usage!
[1:00:46.185817993] [4285] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/v4l-subdev0
[1:00:46.185980398] [4285]  INFO RPI raspberrypi.cpp:1404 Registered camera /base/soc/i2c0mux/[email protected]/[email protected] to Unicam device /dev/media4 and ISP device /dev/media0
[1:00:46.186626927] [4281]  INFO Camera camera.cpp:1035 configuring streams: (0) 4656x3496-BGR888
[1:00:46.187212568] [4285]  INFO RPI raspberrypi.cpp:765 Sensor: /base/soc/i2c0mux/[email protected]/[email protected] - Selected sensor format: 4656x3496-SRGGB10_1X10 - Selected unicam format: 4656x3496-pRAA
[1:00:48.768018322] [4281]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3896-6019b245
[1:00:48.881734702] [4290]  WARN CameraSensorProperties camera_sensor_properties.cpp:174 No static properties available for 'imx519'
[1:00:48.881814256] [4290]  WARN CameraSensorProperties camera_sensor_properties.cpp:176 Please consider updating the camera sensor properties database
[1:00:48.896304081] [4290]  WARN RPI raspberrypi.cpp:1280 Mismatch between Unicam and CamHelper for embedded data usage!
[1:00:48.897929431] [4290] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/v4l-subdev0
[1:00:48.898249520] [4290]  INFO RPI raspberrypi.cpp:1404 Registered camera /base/soc/i2c0mux/[email protected]/[email protected] to Unicam device /dev/media4 and ISP device /dev/media0
[1:00:48.898967770] [4281]  INFO Camera camera.cpp:1035 configuring streams: (0) 1920x1080-BGR888
[1:00:48.899571633] [4290]  INFO RPI raspberrypi.cpp:765 Sensor: /base/soc/i2c0mux/[email protected]/[email protected] - Selected sensor format: 1920x1080-SRGGB10_1X10 - Selected unicam format: 1920x1080-pRAA
[1:00:54.967235560] [4281]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3896-6019b245
[1:00:55.072992055] [4295]  WARN CameraSensorProperties camera_sensor_properties.cpp:174 No static properties available for 'imx519'
[1:00:55.073074536] [4295]  WARN CameraSensorProperties camera_sensor_properties.cpp:176 Please consider updating the camera sensor properties database
[1:00:55.085434812] [4295]  WARN RPI raspberrypi.cpp:1280 Mismatch between Unicam and CamHelper for embedded data usage!
[1:00:55.086454596] [4295] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/v4l-subdev0
[1:00:55.086612538] [4295]  INFO RPI raspberrypi.cpp:1404 Registered camera /base/soc/i2c0mux/[email protected]/[email protected] to Unicam device /dev/media4 and ISP device /dev/media0
[1:00:55.087203124] [4281]  INFO Camera camera.cpp:1035 configuring streams: (0) 4656x3496-BGR888
[1:00:55.087640970] [4295]  INFO RPI raspberrypi.cpp:765 Sensor: /base/soc/i2c0mux/[email protected]/[email protected] - Selected sensor format: 4656x3496-SRGGB10_1X10 - Selected unicam format: 4656x3496-pRAA
[1:00:57.648111342] [4281]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3896-6019b245
[1:00:57.753757765] [4299]  WARN CameraSensorProperties camera_sensor_properties.cpp:174 No static properties available for 'imx519'
[1:00:57.753837134] [4299]  WARN CameraSensorProperties camera_sensor_properties.cpp:176 Please consider updating the camera sensor properties database
[1:00:57.766263631] [4299]  WARN RPI raspberrypi.cpp:1280 Mismatch between Unicam and CamHelper for embedded data usage!
[1:00:57.767321915] [4299] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/v4l-subdev0
[1:00:57.767491061] [4299]  INFO RPI raspberrypi.cpp:1404 Registered camera /base/soc/i2c0mux/[email protected]/[email protected] to Unicam device /dev/media4 and ISP device /dev/media0
[1:00:57.768086702] [4281]  INFO Camera camera.cpp:1035 configuring streams: (0) 1920x1080-BGR888
[1:00:57.768483623] [4299]  INFO RPI raspberrypi.cpp:765 Sensor: /base/soc/i2c0mux/[email protected]/[email protected] - Selected sensor format: 1920x1080-SRGGB10_1X10 - Selected unicam format: 1920x1080-pRAA
[1:01:04.755789863] [4281]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3896-6019b245
[1:01:04.861619950] [4305]  WARN CameraSensorProperties camera_sensor_properties.cpp:174 No static properties available for 'imx519'
[1:01:04.861704708] [4305]  WARN CameraSensorProperties camera_sensor_properties.cpp:176 Please consider updating the camera sensor properties database
[1:01:04.874067058] [4305]  WARN RPI raspberrypi.cpp:1280 Mismatch between Unicam and CamHelper for embedded data usage!
[1:01:04.875084379] [4305] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/v4l-subdev0
[1:01:04.875247451] [4305]  INFO RPI raspberrypi.cpp:1404 Registered camera /base/soc/i2c0mux/[email protected]/[email protected] to Unicam device /dev/media4 and ISP device /dev/media0
[1:01:04.875844981] [4281]  INFO Camera camera.cpp:1035 configuring streams: (0) 4656x3496-BGR888
[1:01:04.876283291] [4305]  INFO RPI raspberrypi.cpp:765 Sensor: /base/soc/i2c0mux/[email protected]/[email protected] - Selected sensor format: 4656x3496-SRGGB10_1X10 - Selected unicam format: 4656x3496-pRAA
[1:01:07.437157159] [4281]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3896-6019b245
[1:01:07.549592851] [4309]  WARN CameraSensorProperties camera_sensor_properties.cpp:174 No static properties available for 'imx519'
[1:01:07.549671850] [4309]  WARN CameraSensorProperties camera_sensor_properties.cpp:176 Please consider updating the camera sensor properties database
[1:01:07.562881857] [4309]  WARN RPI raspberrypi.cpp:1280 Mismatch between Unicam and CamHelper for embedded data usage!
[1:01:07.564269858] [4309] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/v4l-subdev0
[1:01:07.564590947] [4309]  INFO RPI raspberrypi.cpp:1404 Registered camera /base/soc/i2c0mux/[email protected]/[email protected] to Unicam device /dev/media4 and ISP device /dev/media0
[1:01:07.565192032] [4281]  INFO Camera camera.cpp:1035 configuring streams: (0) 1920x1080-BGR888
[1:01:07.565650027] [4309]  INFO RPI raspberrypi.cpp:765 Sensor: /base/soc/i2c0mux/[email protected]/[email protected] - Selected sensor format: 1920x1080-SRGGB10_1X10 - Selected unicam format: 1920x1080-pRAA
[1:01:11.785176058] [4281]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3896-6019b245
[1:01:11.890958813] [4315]  WARN CameraSensorProperties camera_sensor_properties.cpp:174 No static properties available for 'imx519'
[1:01:11.891043719] [4315]  WARN CameraSensorProperties camera_sensor_properties.cpp:176 Please consider updating the camera sensor properties database
[1:01:11.903413217] [4315]  WARN RPI raspberrypi.cpp:1280 Mismatch between Unicam and CamHelper for embedded data usage!
[1:01:11.904441705] [4315] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/v4l-subdev0
[1:01:11.904597573] [4315]  INFO RPI raspberrypi.cpp:1404 Registered camera /base/soc/i2c0mux/[email protected]/[email protected] to Unicam device /dev/media4 and ISP device /dev/media0
[1:01:11.905185455] [4281]  INFO Camera camera.cpp:1035 configuring streams: (0) 4656x3496-BGR888
[1:01:11.905624061] [4315]  INFO RPI raspberrypi.cpp:765 Sensor: /base/soc/i2c0mux/[email protected]/[email protected] - Selected sensor format: 4656x3496-SRGGB10_1X10 - Selected unicam format: 4656x3496-pRAA
[1:01:11.938792214] [4315] ERROR V4L2 v4l2_videodevice.cpp:1234 /dev/video0[14:cap]: Unable to request 1 buffers: Cannot allocate memory
[1:01:11.938897472] [4315] ERROR RPI raspberrypi.cpp:1029 Failed to allocate buffers
Failed to start capture
 i: switch_resolution(): Failed to switch camera resolution.
[1:01:11.940742746] [4315] ERROR Camera camera.cpp:445 Removing camera while still in use
Done bringing up all configured video devices
Scanning again in two minutes
Terminated

Goodbye...

Update: started to print with timelapse on in Octoprint, same problem, after a while webcamd “crashes”.

Looks like the bug is related to the fact, that http://octopi.local/webcam/?action=snapshot takes snapshot with full camera resolution, but at the same time camera is streaming in 1080p resolution and this keeps switching camera modes and that causes out of memory error related to buffers, because buffers are not flushed fast enough to keep up.
For other cameras, like my USB camera, snapshot is taken in the same resolution as the stream is running in.

@Boos

Your analysis is correct.

We will capture the image with the resolution set to maximum and then switch back to the original resolution.

You can capture the resolution of the image with the parameter device.

@Boos

I also experimented with your approach and did have the same problem. I will try to figure out how to fix it.