Pi Camera V3/IMX Chipset Based Cameras Not Working

I have been messing around with ayufan/camera-streamer based on @jneilliii comments on Add support for raspberry pi camera V3.

I was able to get the v3 working without latency I was getting with the earlier process.

I will post my process after I test it with OctoPrint as I tested it on the latest Raspberry Pi 32bit Lite OS.

Make sure to test with the 1.0.0rc3 version of OctoPi image as the base OS will need to be bullseye I think for the camera-streamer app.

The base of the RaspOS 32bit Lite I used is Bullseye.

I manually installed OctoPrint using a guide from this forum and everything is working for me.

Not tested time lapse and I had to create a custom service file to get it to work.

I will be testing the RC3 soon.

I have the same problem, the official TimeLapse doesn't work and the Octolapse Plugin doesn't work with this camera, I also have the problem that the camera connects and disconnects while it is transmitting:

Done bringing up all configured video devices
/root/bin/webcamd: line 116: 8362 Segmentation fault LD_LIBRARY_PATH=. ./m jpg_streamer -o "output_http.so -w $camera_http_webroot $camera_http_options" -i "$input" (wd: /opt/mjpg-streamer)
Scanning again in two minutes

Does anyone know why this could be?
Thanks in advance

I tested RC3 this week using the following process:

sudo systemctl octoprint stop && sudo systemctl disable octoprint
sudo systemctl webcamd stop && sudo systemctl disable webcamd
sudo systemctl ffmpeg_hls stop && sudo systemctl disable ffmpeg_hls
sudo apt-get update && sudo apt-get -y dist-upgrade
sudo reboot
git clone --recursive -j8 GitHub - ayufan/camera-streamer: High-performance low-latency camera streamer for Raspberry PI's
sudo apt-get -y install libavformat-dev libcamera-dev liblivemedia-dev
cd camera-streamer/
make
sudo make install (This takes a while)
sudo reboot
cd camera-streamer/service
sudo nano camera-streamer-pi708-12MP.service
paste below

;
; Official Raspberry Pi v3 12MP camera based on the Sony IMX708 chip
; https://www.raspberrypi.com/products/camera-module-3/
;
[Unit]
Description=camera-streamer web camera
After=network.target
ConditionPathExists=/sys/bus/i2c/drivers/imx708/10-001a/video4linux

[Service]
ExecStart=/usr/local/bin/camera-streamer \
  -camera-path=/base/soc/i2c0mux/i2c@1/imx708@1a \
  -camera-type=libcamera \
  -camera-format=YUYV \
  ; 2304x1296-YUV420
  -camera-width=2304 -camera-height=1296 \
  -camera-fps=30 \
  ; use two memory buffers to optimise usage
  -camera-nbufs=2 \
  ; the high-res is 2304x1296
  -camera-high_res_factor=2 \
  ; the low-res is 576x324
  -camera-low_res_factor=4 \
  ; bump brightness slightly
  -camera-options=brightness=0.1 \
  -rtsp-port

DynamicUser=yes
SupplementaryGroups=video i2c
Restart=always
RestartSec=10
Nice=10
IOSchedulingClass=idle
IOSchedulingPriority=7
CPUWeight=20
AllowedCPUs=1-2
MemoryMax=250M

[Install]
WantedBy=multi-user.target

Ctrl + X to close and Y to save
sudo systemctl enable $PWD/camera-streamer-pi708-12MP.service && sudo systemctl start camera-streamer-pi708-12MP
sudo systemctl enable octoprint && sudo systemctl start octoprint

Webcam feeds works fine using default Webcam settings in Octoprint.

3 Likes

I've written a script based on Dark360's comments. It will install everything and reconfigure boot and systemd to use camera-streamer.

cam3install.sh

[Update 2023-02-05: Updated release in post 72 with 1080p and autofocus.]

#!/bin/bash

# Script to add Raspberry Pi Camera Module 3 to octopi 1.0 RC3
# Combining work from octoprint forums:
# https://community.octoprint.org/t/pi-camera-v3-not-working/49022/16
# https://community.octoprint.org/t/add-support-for-raspberry-pi-camera-v3/49052/5
#
# Tested on a clean install of Jan 20, 2023 Nightly build:
# 2023-01-20_2022-09-22-octopi-bullseye-arm64-lite-1.0.0
#

sudo systemctl stop webcamd && sudo systemctl disable webcamd
sudo systemctl stop octoprint && sudo systemctl disable octoprint
sudo systemctl stop ffmpeg_hls && sudo systemctl disable ffmpeg_hls

sudo apt-get update && sudo apt-get -y dist-upgrade

# do we need to reboot here ? I don't think so

sudo apt-get install -y libavformat-dev libcamera-dev liblivemedia-dev libjpeg-dev
sudo apt install -y cmake libboost-program-options-dev libdrm-dev libexif-dev


git clone --recursive -j8 https://github.com/ayufan/camera-streamer.git
cd camera-streamer/
make
sudo make install

# create 708 service
cat > service/camera-streamer-pi708-12MP.service << EOF
;
; Official Raspberry Pi v3 12MP camera based on the Sony IMX708 chip
; https://www.raspberrypi.com/products/camera-module-3/
;
[Unit]
Description=camera-streamer web camera
After=network.target
ConditionPathExists=/sys/bus/i2c/drivers/imx708/10-001a/video4linux

[Service]
ExecStart=/usr/local/bin/camera-streamer \\
  -camera-path=/base/soc/i2c0mux/i2c@1/imx708@1a \\
  -camera-type=libcamera \\
  -camera-format=YUYV \\
  ; 2304x1296-YUV420
  -camera-width=2304 -camera-height=1296 \\
  -camera-fps=30 \\
  ; use two memory buffers to optimise usage
  -camera-nbufs=2 \\
  ; the high-res is 2304x1296
  -camera-high_res_factor=2 \\
  ; the low-res is 576x324
  -camera-low_res_factor=4 \\
  ; bump brightness slightly
  -camera-options=brightness=0.1 \\
  -rtsp-port

DynamicUser=yes
SupplementaryGroups=video i2c
Restart=always
RestartSec=10
Nice=10
IOSchedulingClass=idle
IOSchedulingPriority=7
CPUWeight=20
AllowedCPUs=1-2
MemoryMax=250M

[Install]
WantedBy=multi-user.target

EOF

# update config.txt
sudo sed -i 's/start_x=1/dtoverlay=imx708/g' /boot/config.txt


#update octopi.txt
cat << EOF | sudo tee -a /boot/octopi.txt > /dev/null

#enable libcamera
camera="libcamera"
camera_libcamera_options="-r 1280x720"
EOF


# enable services

sudo systemctl enable $PWD/service/camera-streamer-pi708-12MP.service
sudo systemctl enable octoprint


#sudo reboot


The script pasted above is what I am using at the time of this post.
The link is to a file in github that I will update as changes are made.

[Update 2023-02-05: Updated release in post 72 with 1080p and autofocus.]

6 Likes

Hi, I've used the script above and the camera is indeed working in Octoprint now(required a couple restarts to show up, but it works), however the image is always out of focus. I cannot find any information anywhere on how to trigger the autofocus built into the module, does anyone know?

Mine seems to be focused correctly, but I wasn't convinced it was autofocusing so much as dumb luck :slightly_smiling_face:

If I figure it out I'll post a followup and update the script. If anyone else figures it out, please feel free to update the script as well.

I've also noticed that the resolution doesn't match what is specified in the service file so there may be an issue passing parameters.

I figured out why you had to reboot a couple times. The service is skipped if the driver hasn't loaded before systemd tries to start it.

I've commented out the ConditionPathExists line and added an ExecPreStart instead. That seems to ensure it tries to restart.

#ConditionPathExists=/sys/bus/i2c/drivers/imx708/10-001a/video4linux

[Service]
ExecStartPre=/usr/bin/test -e /sys/bus/i2c/drivers/imx708/10-001a/video4linux

I've updated the script in github with this change.

2 Likes

Thank you for the script I am going to test it this morning.

do we need to reboot here ? I don't think so
I did this as the whilst reading through the list that sudo apt-get update && sudo apt-get -y dist-upgrade produces, one of the daemons said please reboot. I can remember what it was, so I just thought it was nesscary.

What are these extra packages used for?

sudo apt install -y cmake libboost-program-options-dev libdrm-dev libexif-dev

Big thanks to ltlowe and Dark360

I ran the script and my Camera Module 3 is running great. Script took about 10 minutes to run

Running a fresh install of OctoPi 1.0.0 RC3 on a 4GB Pi 4 Model B

Note that you must not run the script itself as sudo, otherwise git will throw an error

I uncommented the last line and the camera was working as soon as octopi came back up

I'm sure autofocus will be sorted out soon, but for now I've installed the Camera Settings plugin, I selected dw9807 10-000c and that provides a Focus Absolute option that works for manually focusing.

1 Like

@Dark360 Thank you for figuring our what was needed in the first place.

I don't know if the other packages are needed. I pulled together two of your posts to make it work, planning to prune and change as I figure out more. I think those entris were from the other post, but they could be from something I was reading about libcamera.

I've also removed the addition to octopi.txt since it isn't needed when using the streamer.

I've just had a termal runaway so likely won't be trying anymore camera stuff until I figure out the thermal issue :frowning: . I am happy to host the script and any changes in github though.

One last thing is that there is a newer, unreleased version of camera-stream that adds width and height settings for stream and snapshot. I was going to try it and see if it fixed the scaling, but didn't get to it.

Thank you ltlowe and Dark360. I'm not good enough with linux to figure all this out. And the script causes a problem, I ran it line by line and the "make" command gives a long list of error messages, this is a copy of the last line without an error, then a few error messages. It must be user error, but I can't figure it out. Thanks for any help.

[100%] Linking CXX static library libdatachannel-static.a

make[4]: Leaving directory '/home/pi/camera-streamer/third_party/libdatachannel/build'

[100%] Built target datachannel-static

make[3]: Leaving directory '/home/pi/camera-streamer/third_party/libdatachannel/build'

make[2]: Leaving directory '/home/pi/camera-streamer/third_party/libdatachannel/build'

make[1]: Leaving directory '/home/pi/camera-streamer/third_party/libdatachannel/build'

cc -std=gnu17 -MMD -Werror -Wall -g -I/home/pi/camera-streamer -D_GNU_SOURCE -DUSE_FFMPEG -DUSE_LIBCAMERA -I/usr/include/libcamera -DUSE_RTSP -I/usr/include/liveMedia -I/usr/include/groupsock -I/usr/include/BasicUsageEnvironment -I/usr/include/UsageEnvironment -DUSE_LIBDATACHANNEL -Ithird_party/libdatachannel/include -Ithird_party/libdatachannel/deps/json/include -c -o device/buffer.o device/buffer.c

cc -std=gnu17 -MMD -Werror -Wall -g -I/home/pi/camera-streamer -D_GNU_SOURCE -DUSE_FFMPEG -DUSE_LIBCAMERA -I/usr/include/libcamera -DUSE_RTSP -I/usr/include/liveMedia -I/usr/include/groupsock -I/usr/include/BasicUsageEnvironment -I/usr/include/UsageEnvironment -DUSE_LIBDATACHANNEL -Ithird_party/libdatachannel/include -Ithird_party/libdatachannel/deps/json/include -c -o device/buffer_list.o device/buffer_list.c

cc -std=gnu17 -MMD -Werror -Wall -g -I/home/pi/camera-streamer -D_GNU_SOURCE -DUSE_FFMPEG -DUSE_LIBCAMERA -I/usr/include/libcamera -DUSE_RTSP -I/usr/include/liveMedia -I/usr/include/groupsock -I/usr/include/BasicUsageEnvironment -I/usr/include/UsageEnvironment -DUSE_LIBDATACHANNEL -Ithird_party/libdatachannel/include -Ithird_party/libdatachannel/deps/json/include -c -o device/buffer_lock.o device/buffer_lock.c

cc -std=gnu17 -MMD -Werror -Wall -g -I/home/pi/camera-streamer -D_GNU_SOURCE -DUSE_FFMPEG -DUSE_LIBCAMERA -I/usr/include/libcamera -DUSE_RTSP -I/usr/include/liveMedia -I/usr/include/groupsock -I/usr/include/BasicUsageEnvironment -I/usr/include/UsageEnvironment -DUSE_LIBDATACHANNEL -Ithird_party/libdatachannel/include -Ithird_party/libdatachannel/deps/json/include -c -o device/buffer_queue.o device/buffer_queue.c

cc -std=gnu17 -MMD -Werror -Wall -g -I/home/pi/camera-streamer -D_GNU_SOURCE -DUSE_FFMPEG -DUSE_LIBCAMERA -I/usr/include/libcamera -DUSE_RTSP -I/usr/include/liveMedia -I/usr/include/groupsock -I/usr/include/BasicUsageEnvironment -I/usr/include/UsageEnvironment -DUSE_LIBDATACHANNEL -Ithird_party/libdatachannel/include -Ithird_party/libdatachannel/deps/json/include -c -o device/device.o device/device.c

cc -std=gnu17 -MMD -Werror -Wall -g -I/home/pi/camera-streamer -D_GNU_SOURCE -DUSE_FFMPEG -DUSE_LIBCAMERA -I/usr/include/libcamera -DUSE_RTSP -I/usr/include/liveMedia -I/usr/include/groupsock -I/usr/include/BasicUsageEnvironment -I/usr/include/UsageEnvironment -DUSE_LIBDATACHANNEL -Ithird_party/libdatachannel/include -Ithird_party/libdatachannel/deps/json/include -c -o device/device_list.o device/device_list.c

cc -std=gnu17 -MMD -Werror -Wall -g -I/home/pi/camera-streamer -D_GNU_SOURCE -DUSE_FFMPEG -DUSE_LIBCAMERA -I/usr/include/libcamera -DUSE_RTSP -I/usr/include/liveMedia -I/usr/include/groupsock -I/usr/include/BasicUsageEnvironment -I/usr/include/UsageEnvironment -DUSE_LIBDATACHANNEL -Ithird_party/libdatachannel/include -Ithird_party/libdatachannel/deps/json/include -c -o device/links.o device/links.c

cc -std=gnu17 -MMD -Werror -Wall -g -I/home/pi/camera-streamer -D_GNU_SOURCE -DUSE_FFMPEG -DUSE_LIBCAMERA -I/usr/include/libcamera -DUSE_RTSP -I/usr/include/liveMedia -I/usr/include/groupsock -I/usr/include/BasicUsageEnvironment -I/usr/include/UsageEnvironment -DUSE_LIBDATACHANNEL -Ithird_party/libdatachannel/include -Ithird_party/libdatachannel/deps/json/include -c -o output/http_ffmpeg.o output/http_ffmpeg.c

cc -std=gnu17 -MMD -Werror -Wall -g -I/home/pi/camera-streamer -D_GNU_SOURCE -DUSE_FFMPEG -DUSE_LIBCAMERA -I/usr/include/libcamera -DUSE_RTSP -I/usr/include/liveMedia -I/usr/include/groupsock -I/usr/include/BasicUsageEnvironment -I/usr/include/UsageEnvironment -DUSE_LIBDATACHANNEL -Ithird_party/libdatachannel/include -Ithird_party/libdatachannel/deps/json/include -c -o output/http_h264.o output/http_h264.c

cc -std=gnu17 -MMD -Werror -Wall -g -I/home/pi/camera-streamer -D_GNU_SOURCE -DUSE_FFMPEG -DUSE_LIBCAMERA -I/usr/include/libcamera -DUSE_RTSP -I/usr/include/liveMedia -I/usr/include/groupsock -I/usr/include/BasicUsageEnvironment -I/usr/include/UsageEnvironment -DUSE_LIBDATACHANNEL -Ithird_party/libdatachannel/include -Ithird_party/libdatachannel/deps/json/include -c -o output/http_hls.o output/http_hls.c

cc -std=gnu17 -MMD -Werror -Wall -g -I/home/pi/camera-streamer -D_GNU_SOURCE -DUSE_FFMPEG -DUSE_LIBCAMERA -I/usr/include/libcamera -DUSE_RTSP -I/usr/include/liveMedia -I/usr/include/groupsock -I/usr/include/BasicUsageEnvironment -I/usr/include/UsageEnvironment -DUSE_LIBDATACHANNEL -Ithird_party/libdatachannel/include -Ithird_party/libdatachannel/deps/json/include -c -o output/http_jpeg.o output/http_jpeg.c

cc -std=gnu17 -MMD -Werror -Wall -g -I/home/pi/camera-streamer -D_GNU_SOURCE -DUSE_FFMPEG -DUSE_LIBCAMERA -I/usr/include/libcamera -DUSE_RTSP -I/usr/include/liveMedia -I/usr/include/groupsock -I/usr/include/BasicUsageEnvironment -I/usr/include/UsageEnvironment -DUSE_LIBDATACHANNEL -Ithird_party/libdatachannel/include -Ithird_party/libdatachannel/deps/json/include -c -o output/output.o output/output.c

cc -std=gnu17 -MMD -Werror -Wall -g -I/home/pi/camera-streamer -D_GNU_SOURCE -DUSE_FFMPEG -DUSE_LIBCAMERA -I/usr/include/libcamera -DUSE_RTSP -I/usr/include/liveMedia -I/usr/include/groupsock -I/usr/include/BasicUsageEnvironment -I/usr/include/UsageEnvironment -DUSE_LIBDATACHANNEL -Ithird_party/libdatachannel/include -Ithird_party/libdatachannel/deps/json/include -c -o cmd/camera-streamer/http.o cmd/camera-streamer/http.c

cc -std=gnu17 -MMD -Werror -Wall -g -I/home/pi/camera-streamer -D_GNU_SOURCE -DUSE_FFMPEG -DUSE_LIBCAMERA -I/usr/include/libcamera -DUSE_RTSP -I/usr/include/liveMedia -I/usr/include/groupsock -I/usr/include/BasicUsageEnvironment -I/usr/include/UsageEnvironment -DUSE_LIBDATACHANNEL -Ithird_party/libdatachannel/include -Ithird_party/libdatachannel/deps/json/include -c -o cmd/camera-streamer/main.o cmd/camera-streamer/main.c

cc -std=gnu17 -MMD -Werror -Wall -g -I/home/pi/camera-streamer -D_GNU_SOURCE -DUSE_FFMPEG -DUSE_LIBCAMERA -I/usr/include/libcamera -DUSE_RTSP -I/usr/include/liveMedia -I/usr/include/groupsock -I/usr/include/BasicUsageEnvironment -I/usr/include/UsageEnvironment -DUSE_LIBDATACHANNEL -Ithird_party/libdatachannel/include -Ithird_party/libdatachannel/deps/json/include -c -o cmd/camera-streamer/opts.o cmd/camera-streamer/opts.c

cc -std=gnu17 -MMD -Werror -Wall -g -I/home/pi/camera-streamer -D_GNU_SOURCE -DUSE_FFMPEG -DUSE_LIBCAMERA -I/usr/include/libcamera -DUSE_RTSP -I/usr/include/liveMedia -I/usr/include/groupsock -I/usr/include/BasicUsageEnvironment -I/usr/include/UsageEnvironment -DUSE_LIBDATACHANNEL -Ithird_party/libdatachannel/include -Ithird_party/libdatachannel/deps/json/include -c -o cmd/list-devices/main.o cmd/list-devices/main.c

I don't know what's wrong with your system, but I can tell you the steps which absolutely definitely work.

Download the Octoprint RC3 release image here:
https://unofficialpi.org/Distros/OctoPi/nightly/2022-10-27_2022-09-22-octopi-bullseye-armhf-lite-1.0.0.zip

Flash it to a microsd card, boot up the raspberry pi as usual, don't do anything else on it yet.

Log in, either locally or via SSH, doesn't matter.
Then run the following:

wget https://raw.githubusercontent.com/ltlowe/misc/main/cam3install.sh
chmod +x cam3install.sh
./cam3install.sh

restart your system.

That should just work. If it doesn't, then you need to provide more info about what you are actually doing, as there are extremely few steps to this process.

6 Likes

Thank you for the help. And it seems to work, but I get the same series of error messages. Here's what I did:

  • download the file with your link
  • using Raspberry Pi Imager I first formatted the 32GB SD card
  • using Raspberry Pi Imager I flashed the card - I did add these details in the imager:
    • hostname is now MK3S2
    • enabled SSH with password authentication
    • set password for user "pi" to my personal password
    • configured the wireless lan to my own
    • set the local settings to America/Denver and keyboard layout us
    • telemetry is enabled
  • logging in with ssh (this is where the log file starts)
  • following your steps - wget, chmod and running the script
  • at the end of the script the error message appear, but the script continues
  • restarting the pi
  • starting octopi with the ip address
  • runs fine the first time, but I see purple bands in the window on the control screen
  • restarting the system, now the window on the control screen is fine, except the auto focus doesn't work.

So two questions left: why the error messages from the script, and why no auto focus.

The terminal log file is here: Dropbox - cam3install log.txt - Simplify your life

And I'm installing on Raspberry Pi 4 Model B Rev 1.1 with 4GB of memory

Thanks again for your help, Hubert

I believe you are mistaking a verbose compiler output for an error message. The log messages you see are just compiler commands that are being executed as part of the script and those commands contain the -Werror flag.

If you check the source code of the script it calls sudo make install on the camera-streamer source code. If you check the Makefile for camera-streamer you will find -Werror as part of the CFLAGS. This flag is telling the C compiler to treat all compiler warnings as errors (thus failing the compile in case of a warning instead of finishing it).

TL;DR, all seems good and there are no actual warnings or errors in your outputs.

Thanks, and indeed those are warnings. Which were frowned upon when I learned to code, but that is a lifetime ago.

--Hubert

Thanksgambling, ltlowe and Dark360

I finally got this working, on a pi 3, following gamblings instructions precisely.,

In particular, I used the armhf image instead of the 64 bit image.
Also I noticed the admonition to flash the card, boot and do nothing before running the script. In the past I'd restored octoprint from a backup before doing any shell commands.

I don't know if either or both to those things made the difference, but I'm seeing the camera now.

Thanks again!

I also use that exact method and it work direclty! Not even needed to update, they were all already done.

I tested a print, and timelapse with octolapse is working fine!

  1. My focus was not bad, didnt try to play with it. Can someone post common cmd line to adjust manual focus?

  2. I'm an obico (spaguetti detective) user and i just discovered that obico for octoprint is not compatible with Pi OS Bullseye. But Obico for klipper is compatible with 32-bit Raspberry Pi OS version Buster or newer (like bullseye). Someone know if klipper can be installed on this image?
    During this time, i'm using octoeverywhere to view my printer from outside and it work great with the camera.

Thank you.

Will this script work with the 64 bit image (https://unofficialpi.org/Distros/OctoPi/nightly-arm64/2022-10-27_2022-09-22-octopi-bullseye-arm64-lite-1.0.0.zip)?