Webcam Randomly Stops Working

Hi there, merry christmas to all.

An idea for a workaround could be a button in the control interface to restart the camera service:

sudo service webcamd stop
sudo pkill mjpg-streamer
sudo rmmod uvcvideo
sudo modprobe uvcviceo
sudo service webcamd start

Or even better, tracking the service and if it fails run the above commands.

Either way this is only a workaround, it can't be considered a solution...

1 Like

I was suffering from this issue, and found that doing a raspbian OS upgrade has fixed my problem:

sudo apt-get update --fix-missing
sudo apt-get upgrade
sudo reboot

Although I have a rather new installation (less than 30 days ago), my kernel was 2019-09 vintage. The latest kernel is 2020-12.

2 Likes

@Steve_Belt thanks, it seems to have solved it (so far).
Although I just updated to 0.18.rc2, i can't say if is related to that.
The first thing i did was to upgrade everything, then i connected to the web interface.
I haven't run into issues yet...

I'll check it thoroughly through the day and post back later.

Cheers!

the problem is still there.
yesterday it was fine, today i booted the pi, no camera, reboot it was working.
but it stopped when the print started.
at least that's a hint...

i'll start messing with configuration files after the print is finished.

Update: adding -y in octopi.txt seems to have an effect so far.

Update:
Nope, it was only temporary, it persists...
I have some theories. If i come up with something definite or a solution i'll post back.

Sorry for the mess...

EDIT:

Well, i am at 0.18 now, the rc2 lasted two days...

The camera issue was still there. However, a change in /boot/octopi.txt seems to have solved it.

Changing:
camera_usb_options="-r HD -f 30"
to:
camera_usb_options="-r HD -f 25"

seems to behave consistently consistent for the last two days....

My guess is it has to be related to my Microsoft Lifecam linked with mjpg_streamer's implementation.

I did a lot of searching to reach to this conclusion.

I'll have to do thorough crash-testing, bu tif you people have issues, try it with your setup and let me know what happens, i am interested in the findings.

Cheers to everybody.

EDIT:

Go figure...
I tried the camera on my pc, it behaved exactly the same, although it wasn't doing it some months ago...
So it definitely is not even pi related.
I tried with my girlfriends camera - a cheap one - no issues.

I did two things.
First, the usb plug looked rusty to my eyes, so i put in wd40 for about 10-15 minutes and carefully dried it.
Then i very carefully tightened the plug with a plier, the connection felt sort of loose.

It worked fine on the pc for about 10 minutes, then i unplugged it and plugged it to the pi.
It started without the need for an ssh connection, no commandline tinkering at all.
For about an hour now i have no problems....

Weird, i never thought of that...

EDIT:

Go figure...
I tried the camera on my pc, it behaved exactly the same, although it wasn't doing it some months ago...
So it definitely is not even pi related.
I tried with my girlfriends camera - a cheap one - no issues.

I did two things.
First, the usb plug looked rusty to my eyes, so i put it in wd40 for about 10-15 minutes and carefully dried it.
Then i very carefully tightened the plug with pliers, the connection felt sort of loose.

It worked fine on the pc for about 10 minutes, then i unplugged it and plugged it to the pi.
It started without the need for an ssh connection, no commandline tinkering at all.
For about an hour now i have no problems....

Weird...

UPDATE:

Next day, still no issues, i am printing something that is close to1.5 days with one pause so far, not finished yet.

But i still cannot accept that it was only a hardware issue...

UPDATE#2: About 4 hours later, still no hiccups.

UPDATE#3: The Problem came back.
In my frustration i disassembled the camera and saw that a soldering was dodgy (white wire).
Fixed it...
Attaching an image after the repair.

I apologize for all the mess, it was a hardware issue after all...

Hello there,

After being fed up with all those webcam issues, I decided to have a deeper look on Internet. As already said in this thread, nor Octopi or Octoprint is delivering webcam drivers or mjpg_streamer components. The issue is really on Debian side. So, first thing first, let's see if there is any topic related to my webcam on RPI... And I found this tutorial:

I only followed steps 2-3-4, and I was surpised that the guvcview was not installed on my RPI.

BTW, after rebooting, the webcam is streaming fine for the moment. I'll keep you posted if it definitely solves this %*$^Β§!ng problem :smiley:

1 Like

I have two printers at home, and two printers at a makerspace. What has been an interesting case study, is that they all run the exact same OS, edition of octopi, hardware (3B+), and Webcam. 3/4 of them are even MK3s printers.

Two webcam setups at my home are fine, and work 24/7 for months now. At the makerspace #1 is dead, and #2 works intermittently (Will; run for 2-6 days before stopping and requiring a restart).

As best as I can tell, my camera issues stem from a hardware issue. Here's my attempt at a troubleshooting guide brought together from all of the stuff throughout this thread.

  1. Update your OS
sudo apt-get update --fix-missing
sudo apt-get upgrade
sudo reboot
  1. Try a different Webcam/cable.
  2. Try your current webcam on another device to verify it's working for ~12 hours.

There are a bunch of other fixes via software you can try after those, and can be found above. I don't want to list them here, since most of them are hardware specific. In my case, 2/4 of the webcams were dead/dying. My lesson I learned from this thread is that cheaper, or even not so cheap webcams can and will go bad.

Thank you to @agor & @Steve_Belt and everyone else keeping this thread going for so long.

Hi everybody and crashoverride68

More than 5 months after the camera fix, zero issues.

As far as i am concerned the problem is solved.

Best wishes to all.

1 Like

Hi @agor , I ended up here experiencing similar problems. I found a different cause and workaround (RPI4) and I wonder if by any chance the same happened to you, unnoticed.
In my experience, if the frame changes a lot, for exemple I move my hand rapidly in front of the cam, the systems craps out, to the point that /dev/video0 disappears. This happens reliably with the cam connected to a USB2 port, but if it's connected to a USB3 port, then everything is fine. I'm running Ubuntu 21.10
Could it be that initially you had the cam on a slow USB2 port and then while testing it got moved to the faster USB3?

Hi @igor
Kind of sounds funny, igor asking agor...

Anyways, i am also a linux guy, for the last couple of years i'm using arch.
I am using a RPi3 B+ to control my printer, it has 4 usb2 ports.
I haven't noticed the camera giving up on me in similar cases.
For instance when i calibrate the bed with the camera showing the feed, and i move my hands and the printhead around, the camera did not give up.
So i can't really say how an RPi4 behaves...

I have an issue lately with firefox with freezes when i switch to the camera tab.
I am not sure if this is because i updated to the latest firefox or because i changed the settings to have it load exclusively to ram, trying to minimize disk writes on my nvme - maybe its overkill...
Chromium behaves nicely though, so i haven't looked deeper into it.

PS: I forgot to mention, i was having camera issues with my desktop machine too, that's what made me think it was a hardware issue.
Opening cheese and switching to video resulted in the camera crapping out after a few seconds.
Besides, the camera is supposed to be a usb2 device.
I can't remember if i tried connecting it to a usb3 port, but the soldering i did definitely solved my problems.

Hi all, I am having this same issue. My Raspberry Pi camera only works for a few minutes at a time. If I ssh into the pi and run sudo service webcamd restart or reboot the pi the camera begins to work again but will stop working again shortly after. Any recommendations?

Complete hack but this wrapper might get you through a print if you absolutely need the webcam but haven't gotten to the root of the issue.

while true; do if sudo service webcamd status | grep timeout > /dev/null; then echo "starting"; sudo systemctl restart webcamd; fi; sleep 15; done

Every 15 seconds this will check the status for the error and then send the restart command to systemctl if the error is in the contents of the status message. In my case it was a timeout error. I have no idea how to fix this timeout or how to tune it to something longer so I just push this to nohup and everything seems to be okay for the most part.

Still going on in 2023, with a pretty much new installation. Raspberry Pi 4 with the High Quality Camera.

Eventually the Webcam just stops working, and rebooting usually restores it. But today it didn't. Nothing changes in the system between these episodes, either.

None of the command-line suggestions here worked. The webcamd one resulted in: Unit webcamd.service not found.

Do you know if you using the 'new camera stack' image, or the old one?

Thanks for the reply. Presumably the new one, because I didn't select the "use old camera stack" option.

Just updated OctoPrint (after being notified of an update available) and I don't see that checkbox anywhere now. I don't know if that's because the webcam's not currently working, or what.

The new camera stack isn't an option that's available anywhere on the UI, but rather a decision you have to make when flashing the image. Either you select "OctoPi (stable)" or "OctoPi (new camera stack)"

Right, I couldn't remember where I'd seen the option. I'm pretty sure I picked the new stack.

Today it still wasn't working, so I cut power to everything and restarted; it's working for the moment.

This really worked for me!

For anyone on the newest (as of early 2024) webcam stack. This fixes it for me:

sudo kill $(pgrep camera-streamer)

Internally it will lead to the camera-streamer getting restarted.