Webcam randomly stops working - Logitech C920X

Camera model
Logitech C920X

What is the problem?
The camera will show output just fine to Obico, Octoapp, and Octoprint and then it will periodically (without reason so far) stop functioning. It will sometimes come back on its own but most of the time a reboot is necessary.

What did you already try to solve it?
I have increased the video RAM to 256 from 128, I we scoured the forums and logs to try and make sense of any errors that will spell out the issue. I have updated the Octopi and validated that there are no updates for the Octoprint instance. I am using the power cord from the Rasperry Pi4B kit

RAK Raspberry Pi 4 Kit – RAKwireless Store

Logs (/var/log/webcamd.log, syslog, dmesg, ... no logs, no support)
Partial of webcamd.log
Starting up webcamDaemon...

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

Explicitly 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
config file='/boot/octopi.txt':USB device was not set in options, start MJPG-streamer with the first found video device: /dev/video0
<13>Jan 27 16:13:31 root: Starting USB webcam
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-octopi -n -i input_uvc.so -r 1920x1080 -f 30 -d /dev/video0
    MJPG Streamer Version: git rev: 5554f42c352ecfa7edaec6fc51e507afce605a34
    i: Using V4L2 device.: /dev/video0
    i: Desired Resolution: 1920 x 1080
    i: Frames Per Second.: 30
    i: Format............: JPEG
    i: TV-Norm...........: DEFAULT
    libv4l2: error setting pixformat: Device or resource busy
    Unable to set format: 1196444237 res: 1920x1080
    Init v4L2 failed !! exit fatal
    i: init_VideoIn failed

Partial of syslog
Jan 27 16:14:18 raspberrypi root: Starting USB webcam
Jan 27 16:14:18 raspberrypi MJPG-streamer [28759]: starting application
Jan 27 16:14:18 raspberrypi MJPG-streamer [28759]: MJPG Streamer Version: git rev: 5554f42c352ecfa7edaec6fc51e507afce605a34
Jan 27 16:14:18 raspberrypi MJPG-streamer [28759]: Using V4L2 device.: /dev/video0
Jan 27 16:14:18 raspberrypi MJPG-streamer [28759]: Desired Resolution: 1920 x 1080
Jan 27 16:14:18 raspberrypi MJPG-streamer [28759]: Frames Per Second.: 30
Jan 27 16:14:18 raspberrypi MJPG-streamer [28759]: Format............: JPEG
Jan 27 16:14:18 raspberrypi MJPG-streamer [28759]: TV-Norm...........: DEFAULT
Jan 27 16:14:18 raspberrypi MJPG-streamer [28759]: init_VideoIn failed
Jan 27 16:14:19 raspberrypi systemd[1]: webcamd.service: Succeeded.
Jan 27 16:14:19 raspberrypi systemd[1]: Started the OctoPi webcam daemon with the user specified config.
Jan 27 16:14:20 raspberrypi systemd[1]: webcamd.service: Service RestartSec=1s expired, scheduling restart.
Jan 27 16:14:20 raspberrypi systemd[1]: webcamd.service: Scheduled restart job, restart counter is at 256.
Jan 27 16:14:20 raspberrypi systemd[1]: Stopped the OctoPi webcam daemon with the user specified config.
Jan 27 16:14:20 raspberrypi systemd[1]: Starting the OctoPi webcam daemon with the user specified config...
Jan 27 16:14:20 raspberrypi root: Starting USB webcam
Jan 27 16:14:20 raspberrypi MJPG-streamer [28785]: starting application
Jan 27 16:14:20 raspberrypi MJPG-streamer [28785]: MJPG Streamer Version: git rev: 5554f42c352ecfa7edaec6fc51e507afce605a34
Jan 27 16:14:20 raspberrypi MJPG-streamer [28785]: Using V4L2 device.: /dev/video0
Jan 27 16:14:20 raspberrypi MJPG-streamer [28785]: Desired Resolution: 1920 x 1080
Jan 27 16:14:20 raspberrypi MJPG-streamer [28785]: Frames Per Second.: 30
Jan 27 16:14:20 raspberrypi MJPG-streamer [28785]: Format............: JPEG
Jan 27 16:14:20 raspberrypi MJPG-streamer [28785]: TV-Norm...........: DEFAULT
Jan 27 16:14:21 raspberrypi MJPG-streamer [28785]: init_VideoIn failed
Jan 27 16:14:21 raspberrypi octoprint[433]: #033[33m2023-01-27 16:14:21,745 - octoprint.plugins.octoapp - WARNING - Failed to get webcam snapshot HTTPConnectionPool(host='127.0.0.1', port=8080): Read timed out. (read timeout=5.0)#033[0m
Jan 27 16:14:21 raspberrypi systemd[1]: webcamd.service: Succeeded.
Jan 27 16:14:21 raspberrypi systemd[1]: Started the OctoPi webcam daemon with the user specified config.
Jan 27 16:14:22 raspberrypi octoprint[433]: 2023-01-27 16:14:22,911 - backoff - INFO - Backing off capture_jpeg(...) for 1.2s (requests.exceptions.ReadTimeout: HTTPConnectionPool(host='127.0.0.1', port=8080): Read timed out. (read timeout=5))#033[0m
Jan 27 16:14:23 raspberrypi systemd[1]: webcamd.service: Service RestartSec=1s expired, scheduling restart.
Jan 27 16:14:23 raspberrypi systemd[1]: webcamd.service: Scheduled restart job, restart counter is at 257.
Jan 27 16:14:23 raspberrypi systemd[1]: Stopped the OctoPi webcam daemon with the user specified config.
Jan 27 16:14:23 raspberrypi systemd[1]: Starting the OctoPi webcam daemon with the user specified config...
Jan 27 16:14:23 raspberrypi root: Starting USB webcam
Jan 27 16:14:23 raspberrypi MJPG-streamer [28814]: starting application
Jan 27 16:14:23 raspberrypi MJPG-streamer [28814]: MJPG Streamer Version: git rev: 5554f42c352ecfa7edaec6fc51e507afce605a34
Jan 27 16:14:23 raspberrypi MJPG-streamer [28814]: Using V4L2 device.: /dev/video0
Jan 27 16:14:23 raspberrypi MJPG-streamer [28814]: Desired Resolution: 1920 x 1080
Jan 27 16:14:23 raspberrypi MJPG-streamer [28814]: Frames Per Second.: 30
Jan 27 16:14:23 raspberrypi MJPG-streamer [28814]: Format............: JPEG
Jan 27 16:14:23 raspberrypi MJPG-streamer [28814]: TV-Norm...........: DEFAULT
Jan 27 16:14:23 raspberrypi MJPG-streamer [28814]: init_VideoIn failed
Jan 27 16:14:24 raspberrypi octoprint[433]: #033[31m2023-01-27 16:14:24,238 - octoprint.plugins.obico - ERROR - timed out#033[0m
Jan 27 16:14:24 raspberrypi systemd[1]: webcamd.service: Succeeded.
Jan 27 16:14:24 raspberrypi systemd[1]: Started the OctoPi webcam daemon with the user specified config.
Jan 27 16:14:24 raspberrypi octoprint[433]: #033[31m2023-01-27 16:14:24,273 - webcam_server - ERROR - Exception on / [GET]#033[0m
Jan 27 16:14:24 raspberrypi octoprint[433]: Traceback (most recent call last):
Jan 27 16:14:24 raspberrypi octoprint[433]: File "/home/pi/oprint/lib/python3.7/site-packages/flask/app.py", line 2073, in wsgi_app
Jan 27 16:14:24 raspberrypi octoprint[433]: response = self.full_dispatch_request()
Jan 27 16:14:24 raspberrypi octoprint[433]: File "/home/pi/oprint/lib/python3.7/site-packages/flask/app.py", line 1519, in full_dispatch_request
Jan 27 16:14:24 raspberrypi octoprint[433]: rv = self.handle_user_exception(e)
Jan 27 16:14:24 raspberrypi octoprint[433]: File "/home/pi/oprint/lib/python3.7/site-packages/flask/app.py", line 1517, in full_dispatch_request
Jan 27 16:14:24 raspberrypi octoprint[433]: rv = self.dispatch_request()
Jan 27 16:14:24 raspberrypi octoprint[433]: File "/home/pi/oprint/lib/python3.7/site-packages/flask/app.py", line 1503, in dispatch_request
Jan 27 16:14:24 raspberrypi octoprint[433]: return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
Jan 27 16:14:24 raspberrypi octoprint[433]: File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_obico/webcam_stream.py", line 484, in webcam
Jan 27 16:14:24 raspberrypi octoprint[433]: return self.get_snapshot()
Jan 27 16:14:24 raspberrypi octoprint[433]: File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_obico/webcam_stream.py", line 422, in get_snapshot
Jan 27 16:14:24 raspberrypi octoprint[433]: return flask.send_file(io.BytesIO(self.next_jpg()), mimetype='image/jpeg')
Jan 27 16:14:24 raspberrypi octoprint[433]: File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_obico/webcam_stream.py", line 427, in next_jpg
Jan 27 16:14:24 raspberrypi octoprint[433]: s.connect(('127.0.0.1', 14499))
Jan 27 16:14:24 raspberrypi octoprint[433]: socket.timeout: timed out
Jan 27 16:14:24 raspberrypi octoprint[433]: 2023-01-27 16:14:24,278 - werkzeug - INFO - 127.0.0.1 - - [27/Jan/2023 16:14:24] "#033[35m#033[1mGET /?action=snapshot HTTP/1.1#033[0m" 500 -#033[0m
Jan 27 16:14:25 raspberrypi systemd[1]: webcamd.service: Service RestartSec=1s expired, scheduling restart.
Jan 27 16:14:25 raspberrypi systemd[1]: webcamd.service: Scheduled restart job, restart counter is at 258.
Jan 27 16:14:25 raspberrypi systemd[1]: Stopped the OctoPi webcam daemon with the user specified config.
Jan 27 16:14:25 raspberrypi systemd[1]: Starting the OctoPi webcam daemon with the user specified config...
Jan 27 16:14:25 raspberrypi root: Starting USB webcam
Jan 27 16:14:25 raspberrypi MJPG-streamer [28846]: starting application
Jan 27 16:14:25 raspberrypi MJPG-streamer [28846]: MJPG Streamer Version: git rev: 5554f42c352ecfa7edaec6fc51e507afce605a34
Jan 27 16:14:25 raspberrypi MJPG-streamer [28846]: Using V4L2 device.: /dev/video0
Jan 27 16:14:25 raspberrypi MJPG-streamer [28846]: Desired Resolution: 1920 x 1080
Jan 27 16:14:25 raspberrypi MJPG-streamer [28846]: Frames Per Second.: 30
Jan 27 16:14:25 raspberrypi MJPG-streamer [28846]: Format............: JPEG
Jan 27 16:14:25 raspberrypi MJPG-streamer [28846]: TV-Norm...........: DEFAULT
Jan 27 16:14:25 raspberrypi MJPG-streamer [28846]: init_VideoIn failed

Additional information about your setup (OctoPrint version, OctoPi version, ...)
octoprint-systeminfo-20230127161527.zip (1.8 MB)

Having the same issue. The camera worked the first time, but has not worked since. Adding my comment to follow progress. If you find a solution please post it here.

Since you mentioned using Obico, then it is likely that Obico's own streaming implementation is at work here - notice that webcamd failed to start streaming.

Try it with Obico disabled to see if it might be an issue with your webcam, or the specific way it's being streamed. After disabling Obico you'll likely have to restart webcamd.

I disabled Obico and it did not resolve things. At this point I did get my camera working but I can not guarantee that it will stay that way.

I had tried many options including adding -y to usb options with no luck.
Adding the cameras USBID to additional_brokenfps_usb_devices=()
and so much more.

When looking at my webcamd.log I noticed that it appeared that MJPG-streamer was trying to use the first found USB camera which in the logs sometimes would be Video10 and other times Video0. I also saw errors related to invalid height and width.

So I looked into the mjpg-streamer configuration options and decided to use the -d parameter.

Some of the steps below come from Install both a Raspberry PI Camera and a USB Camera on Octopi 0.17 and 0.18 — Federico Hatoum

Here are the steps I took to get it working:

Unplug the camera from USB
SSH into Pi
Capture USB messages

sudo tail -f /var/log/messages | sudo tee ~/camera.txt

Plugin the USB Camera
Ctrl+C the tail

sudo nano ~/camera.txt

You’ll need the values for idVendor, idProduct and serial

Create (or edit if existing) USB rules file

sudo nano /etc/udev/rules.d/99-usb.rules

Add the following line to the file:

SUBSYSTEM=="video4linux", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="08e5", ATTRS{serial}=="6FA0BD5F", SYMLINK+="LogitechWebCam"

These are the values I found in my log for my camera (a Logitech C920x Pro HD webcam) — you’ll need to use your values for idVendor, idProduct and serial. For SYMLINK, use whatever name you want to give your camera. You’ll use the name in upcoming steps.

Verify USB Rules

Before moving on to the next, confirm that the camera you configured in the previous udev USB rules step is working properly. If it isn’t, then none of the steps that follow will work.

Reboot the Raspberry PI to make it read the settings in 99-usb.rules and connect your camera.

sudo reboot

Once your PI is back up, ssh into it again and type the following command to list all the devices under the /dev directory:

ls -la /dev

If 99-usb.rules was read correctly at startup, you should find the symlink you created under /dev.

The -> character next to LogitechWebCam indicates that a symbolic link to the video0 device called LogitechWebCam.

Edit octopi.txt

Under /boot there is an octopi.txt file which is a configuration file for the webcamd service. We need to edit that file to point to our symbolic link.

sudo nano /boot/octopi.txt

Change the text camera="raspi" (or it might be camera="auto") to camera="usb".

Change camera_usb_options to point to the symbolic link by adding the -d parameter with the name you gave your USB camera.

My example
camera_usb_options="-d /dev/LogitechWebCam -r 1280x720 -f 10"

  • NOTE: Be conservative with your resolution and framerate settings. A Logitech C920 can support 1920x1080 at 30 frames per second, but at that level I recommend a Pi 4 4gb. For a Pi 3, I recommend setting USB cameras as 1280x720 and 10 fps.

Hope this helps someone else.

@VileAce - What you suggested appears to be working so far. I appreciate the support. This has been a tough one to track down honestly. I am appreciative of the support I got. Thanks again.

I know how you feel, I spent over 7 hours yesterday trying to get it to work. I'm an crossing my fingers that it keeps working.

For anyone else reading this. If it continues to work long term, I will do a complete guide starting from the beginning. I knew that rashuge and I were at a similar place and had the base knowledge so I left out some of the early detail.

Thank you, VileAce for the amazing explanation! Unfortunately I found this thread completely by accident a week too late. I tried so hard to find a solution for this exact same thing, and the only solution I came across was on a Reddit post, where someone suggested connecting the camera (Logitech C930e in my case) through a powered USB hub. I ordered one on Amazon fo $8, and this did the trick for me. My webcam used to shut down on every single print, and it now hasn't shut down in a full week of printing. I'm glad to know there are other ways of solving this, and I saved this thread in case my current solution fails at some point.

Thanks for the information. Just to let everyone know. I have been running with the described configuration for the last 10 days with zero issues.