Using libcamera & imx519 on OctoPi

This post describes how to use libcamera & imx519 on OctoPi Nightly build.

1 Like

SD Card image:

System information:

[email protected]:~ $ uname -a
Linux octopi 5.10.92-v7l+ #1514 SMP Mon Jan 17 17:38:03 GMT 2022 armv7l GNU/Linux

[email protected]:~ $ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 11 (bullseye)
Release:        11
Codename:       bullseye

Install dependencies

Install the Driver(Example using imx519)

# Agree to restart after installation
wget -O
chmod +x
./ -p imx519_kernel_driver

libcamera-dev and libcamera-apps Installation

./ -p libcamera_dev
./ -p libcamera_apps


Check video device:

Run the libcamera example to see if the image can be capture normally.

libcamera-still -t 5000 -o test.jpg -n

Download libcamera plugin source code

Clone mjpg-streamer source code and execute the following commands, compile and install the libcamera plugin.

git clone mjpg-streamer-libcamera
cd mjpg-streamer-libcamera/mjpg-streamer-experimental
sudo install -m 755 _build/mjpg_streamer /opt/mjpg-streamer
sudo find _build -name "*.so" -type f -exec install -m 644 {} /opt/mjpg-streamer \;
sudo cp -a -r ./www /opt/mjpg-streamer
sudo chmod 755 /opt/mjpg-streamer/www
sudo chmod -R 644 /opt/mjpg-streamer/www

Modify the octopi.txt file

Edit /boot/octopi.txt, and make the following changes

  1. Configure which camera to use
# If it's just a test, only this line is enough, 
# and the prest are defaults if they are not set. 
# Only the simplest configuration is demonstrated here.

like this:

  1. Set parameters for libcamera plugin.

Parameter details can be viewed using the following command.

./mjpg_streamer -i " -h"

  1. Configuration of camera HTTP output

You can also use the command to view the camera_http_options parameter.

./mjpg_streamer -o " -h"

Replace webcamd file

webcamd is in the /root/bin directory.

You can change the name of the original file to achieve the purpose of backup.Then copy our modified webcamd to the /root/bin directory.

In the example we downloaded the new file to the /home/pi directory.

cd ~
sudo mv /root/bin/webcamd /root/bin/webcamd.bak
sudo wget -O webcamd
sudo mv webcamd /root/bin/
sudo chmod 755 /root/bin/webcamd

Reboot your Pi

sudo reboot

View in browser


Enter the device IP address(ipv4 address) in the browser address bar.

Click on the label pointed by the red arrow in the image below to view the image captured by the camera.


Install control plugin

Click the button pointed by the arrow in the image below.

Follow the instructions to complete the plugin download.

Copy the link to the location outlined in the diagram.

Finally, follow the prompts on the page to restart the service.

sudo reboot

You can use this plugin to achieve manual focus.

Hi, thanks a lot for the detailed guide!

I’ve been trying all day without any luck. My first attempts have been using Octopi stable release which is not the same as this guide so I don’t expect to have a success, however I was able to run the test successfully. My problem came when I had to compile mjpg_streamer. It failed as there was something wrong with libcamera dependencies.

Later on I have done one last attempt using the 1.0.0 RC 1 of Octopi which is based on bullseye, as this guide. But in this case I’m not even able to run the test picture. This is what I get in the logs:

[email protected]:~ $ libcamera-still -t 5000 -o test.jpg -n
[0:22:02.119116033] [2582] INFO Camera camera_manager.cpp:293 libcamera v0.0.0
[0:22:02.137264505] [2583] WARN CameraSensorProperties camera_sensor_properties.cpp:141 No static properties available for ‘imx519’
[0:22:02.137305449] [2583] WARN CameraSensorProperties camera_sensor_properties.cpp:143 Please consider updating the camera sensor properties database
[0:22:02.137350503] [2583] ERROR CameraSensor camera_sensor.cpp:551 ‘imx519 10-001a’: Camera sensor does not support test pattern modes.
[0:22:02.155070150] [2583] WARN RPI raspberrypi.cpp:1233 Mismatch between Unicam and CamHelper for embedded data usage!
[0:22:02.155676861] [2583] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/v4l-subdev0
[0:22:02.156020224] [2583] INFO RPI raspberrypi.cpp:1356 Registered camera /base/soc/i2c0mux/[email protected]/[email protected] to Unicam device /dev/media0 and ISP device /dev/media3
[0:22:02.156646841] [2582] INFO Camera camera.cpp:1028 configuring streams: (0) 2328x1748-YUV420
[0:22:02.157003686] [2583] ERROR V4L2 v4l2_videodevice.cpp:985 /dev/video0[12:cap]: Unable to set format: Device or resource busy
[0:22:02.157415678] [2583] ERROR V4L2 v4l2_videodevice.cpp:1179 /dev/video0[12:cap]: Unable to request 0 buffers: Device or resource busy
ERROR: *** failed to configure streams ***

I’m using a Raspberry Pi 4 8GB with this OctoPi image.

Any idea what could be wrong?

Thanks in advance.

Edit: I’ve found this in dmesg logs. Maybe it’s relevant.

[ 99.256385] unicam fe801000.csi: Wrong width or height 640x480 (remote pad set to 4656x3496)
[ 99.256398] unicam fe801000.csi: Failed to start media pipeline: -22

This is because the mjpg-streamer that comes with OctoPi running, it occupies the /dev/video0 node, and this problem can be solved when you replace the mjpg-streamer.
In addition, you can release the occupation of video0 by closing the current mjpg-streamer service:
Check service status:

sudo systemctl status webcamd.service

Shut down the service:

sudo systemctl stop webcamd.service

Any error messages?

Thank you so much! I tried what you suggested and worked like a charm. I was also able to compile mjpg_streamer and now everything seems working as expected.

I have an IMX298 which I am trying to do the same thing with. I have run it on a full blown bare version of RPi with linux, minus Octopi. When I tried, I had no success after adding Octoprint to it and then trying to get the camera to be detected.

After talking with Customer Support for Arducam, I was pointed to this page. I did install the given Octopi image and tried to install the kernal , but with the IMX519 as mentioned. When I try to detect any video, it is not detecting the IMX298. Anyone else tried installing an IMX298 for use with Octopi? If someone with more kernel driver knowledge could point me towards what may need to happen next in order to get a 298 working, it would be appreciated.

This post just uses the IMX519 as an example, if you are using Pivariety please install the Pivariety driver:

For others:

If you have related questions, please open another post with a link to this post.

1 Like

What’s wrong with the pictures? I can’t see some pictures in this post.