Octoprint causing Firefox to hang when loading Webcam

I have been using Octoprint (1.3.9 running on A Pri3 & OctoPi 0.15.0PE) for some weeks with little issue and connect to us using Firefox under Win7 and Safari on an iPad.

But suddenly I have found that on my PC (Firefox) as soon as I hit the "Control" section, the browsers tab hangs. Generally I see the "Webcam Stream Loading" message, but occasionally a still frame appears.. But after this the browser is totally unresponsive and has to be restarted..

Looking at the task manager, Firefox's starts to consume a huge amount of memory... When I launch Octoprint Firefox is using around 300MB.. But as soon as I hit the 'control' button, it immediatly ramps up for over 2.5GB at which point I have to either close the tab, or even kill the Firefox process.

I tried with Chrome and IE (Although IE does not open the Webcam) thats perfect.

I have also found that Safari on my iPad works fine, so this just appears to be a Firefox issue.. As a final test I tried with my works laptop and I get the same behavour (i.e Chrome is fine, but Firefox not).

So this seems to be a general firefox issue.. I hope there is a solution to this as I am a Firefox user and Octoprint is totally unusable for me right now..

1 Like

I just tried this in

image

and cannot reproduce this. Could it be one of your installed browser extensions?

This post was flagged by the community and is temporarily hidden.

No idea. But to rule out an extension or some setting I'd try a fresh profile just in case. And then I'd compare version numbers. You could also try what happens when you access the webcam stream directly in your browser instead of going via the control tab, maybe that shows a different behaviour which could hint at things.

Thing is, right now it's hard to say really what's going wrong there for you, I just see that it's working fine over here and I haven't heard anything else about it, so it can't be a general issue with Firefox and MJPG streams.

You also didn't say that you changed anything in your OctoPrint setup, so that sounds more like whatever made it go from working to not working must have been something specific to your browser environment.

This post was flagged by the community and is temporarily hidden.

Firefox is known to pull the hand brake from now to the without reason.
I'm running Waterfox with no issue for months now.

That at least rules out anything in OctoPrint's UI as the culprit then. Googling for general memory leak issues with FF and mjpeg streams does yield quite a number of results, but all of those are claimed as fixed years ago. Odd.

OK.. I have been doing some testing and have uncovered some really odd things.

First of all, visiting the Stream URL:

http://192.168.1.119:8080/?action=stream

Sometimes i get a black screen and memory consumption, but most of the time it works and gives real time video...

So as a test I dug out my old Laptop which is running Win7 and an old version of Firefox (v41) and Octoprint works fine.

Firefox then did an auto update to v43 and Octoprint still worked
Then I had an auto update to V47 and Octoprint was fine
But then I had a an update to V56 (Quantum) and had the same issue as I have on my other PCs
It then did another update to V57 and it was the same (broken)
And finally V63 (the latest) and its the same as my work laptop and PC.

So I now have 3 PCs, all running the latest Firefox and all have the same problem.

But here is where it gets weird.. If I put my old PC in the "Webcam Stream loading" mode where memory is rampining up.. I have been able to get the Webcam to load on the other 2 PCs with no memory consumption.. And when it works and I can move the printer around and the video is smooth and lag free...

I can't do this every time, but perhaps 8 out of 10.. (The other 2 just get into the Memory Leak mode).

So I can say with near certainty that something changed after Firefox v47 which appears to be causing this.. But its odd that I am the only person to see it...

I am not sure if this means anything to any one.. The obvious soluition here is to stop using Firefox, but thats a bit drastic and I would like to avoid that if possible.

Hi Foosel.. What resolution are you running your camera? I have a feeling this problem is to do with running 1920x1080...

I am just doing some tests now, but 640x480 works fine..

I am also seeing some curious things when running 2 streams at the same time.. If I open one instance of the GUI and then get it to hang/consume memory.. Then I open another, sometimes this allows one (or both) to open and the memory reduces to normal.

This is very similar to what I saw this afternoon, when I had another laptop hung on Webcam loading.. WHen it was in this state, I was often able to get the webcam stream to open on another PC...

I just tried at 1280x768 and have the same issue.. And I KNOW with certainty that this worked before....

After more testing Resolution certainly has something to do with it.

640x480 and 800x600 work fine in Firefox for sure..... But higher resolutions start to cause problems....

My test was with 720p I think. I'll try to find the time to test with an RPi cam module at 1080p.

Its odd 720p (1280x768) worked perfectly for me until I moved the printer.. Now the highest I can go with Firefox is 800x600..

The only explanation I have for that is that in the old location, I had high latency and packet loss, which perhaps that actually helped. When it was like this, the video was delayed 10-20 seconds...

So perhaps now that I have no latency/packet loss, the stream takes more bandwidth and causes the problem I see in Firefox.. Thats the only theory I can come up with...

Ideally I would like to use 1920x1080... But I guess right now I either have to decide between low res and Firefox or hi-res and Chrome.

I still can't work out exactly whats going on.. Sometimes I can get the "Stream" to load just by connecting to port 8080.. Othertimes it hangs and gets into the memory loop...

And as I said, if I have 2 tabs pointing to the stream, or even another PC connected (And hung) I can sometimes get the Webcam to load in Firefox..

Its clearly a Firefox thing.. But odd that it appears to have started in v56 and no-one else has reported this...

I think I may have just made some progress.. After typing my last comment I started to think about bandwidth and how Firefox may just be getting "swamped".. So rather than focus on Resolution, I also looked at FPS.

And now I am running 1920x1080 again, but only 5fps.. And Its working in Firefox.

So I just think that Firefox can't cope with the data rates that high Resolutions/FPS video stream generate... Strange, as it copes with 4K Youtube OK.

I am going to keep testing to see if I can find the limits...

Edit: At 1080p, 5fps works 10fps doesn't... I just discovered the "quality" switch and am now making some real progress.. Quality of 1 has allowed me to get to 30fps... But the picture quality is very poor (obviously) so working now to find an acceptable balance..

That isn't MJPG though but some actual video codec (probably webm or H264), so there might simply be an issue in the MJPG bits of Firefox there. The ancient tickets I found were - as far as I could tell - all related to not giving free the past frames. So maybe they fixed that, but the freeing doesn't happen fast enough for higher frame rates... Just blindly guessing here. I'm currently looking into some stuff for 1.3.10rc3, but hopefully will be able to tell you how 1080p performs here later today.

At 1080p, 5fps works 10fps doesn't... I just discovered the "quality" switch and am now making some real progress.. Quality of 1 has allowed me to get to 30fps... But the picture quality is very poor (obviously) so working now to find an acceptable balance..

Do you by chance know of a way to restart the webcam process when changing the /boot/octopi.txt settings.. That would speed things up as I am having to reboot after each change.

Yes, SSH in and then sudo service webcamd restart should do the trick.

1 Like

That perfect.. Really help me speed up my tests.. So it seems that at 1920x1080 the highest "quality" I can go is 10.. Anything higher to start to get unstable and at 15, I just get the standard memory hang.

I really hope you can find a way to do something about this as this is causing me a huge problem now.

Fingers crossed

Jon

Sorry, but I won't be able to do that. From the sounds of it, it's a browser bug with MJPG streams, and I can't fix browser bugs. OctoPrint doesn't produce that stream, it merely embeds it. mjpg-streamer does, at least on OctoPi, and that's not a software under my control either. So the best that can come out of this is me checking if I can reproduce this at all and if so add some FAQ entry on avoiding high frame rates with Full HD content in Firefox. But that's really all.

So, I just tested this with an RPi3, RPi cam @ 1080p30fps, connected to the same switch as my work PC via ethernet. No reproduction. It's not really 30fps as far as I can tell, but I also am not seeing any kind of memory leak.

I wasn't expecting you to come up with some magic fix.. Clearly this is a Firefox issue, or atleast something with the Webcamd service.. And know its out of your control..

I have been playing around, and had good results at 10 fps with a quality of 65... But I just decided to increase the frame rate to see when it started to go bad.. I tried 12.. Then 15.. Then back to 30 and its working fine.. so then I increased the quality and got that back up to 100.

Right now, I have it working 1920x1080 at 30fps and Quality of 100 and I don't know how or why.. I can kill off the tab or browser and re-attach to Octopint and when I hit control the webstream appears INSTANTLY...

Its never done this before and I don't know why its working now.. But I can say with near certainty that the fault will return.

I think I am just going to find a resolution/quality/frame rate which works and live with it....

Edit: Tried another resolution/frame rate and then went back to 1920x1080 and the problem has returned.. Its very flaky for sure!