Another Webcam Issue. Looks like its changing the URL?

Just set up Octoprint on an existing Raspbian installation and everything has been working wonderfully. I already had a UV4L streaming server set up on my Pi accessible from 'http://192.168.1.21:8080/stream/video.mjpeg'.

Dropping the URL in the settings box and hitting TEST shows the stream just fine, but in the control tab, I get the Webcam stream not loaded message while showing a very functional link (I can click on it and see the stream).

Investigating further, It seems that the URL the site is actually using has some additional information tacked on to the end (looks like a timestamp) that is causing a 404.Any reason for this or solutions for fixing this?

I think I've heard others call this a nonce, a random or sequential number added to a URL to prevent browser caching. So enter then entire URL, as decorated, into another tab of your browser and see if that works. If it does, then you can ignore the nonce decoration at the end. If it doesn't work in the new tab with the nonce then let us know.

I think something has changed with the streaming urls in this version. :8080 quit working for me (but /webcam/ still works), and I had to change the default webcam template for my plugin.

Try changing your URL in OctoPrint Settings->Webcam to this:

/webcam/?action=stream

Edit:

I didn't notice that you were using a different streaming method. Maybe this instead:

/webcam/stream/video.mjpeg

I'm less sure now that my advice will help you at all though :frowning:

I read that as "the url changed from /webcam/stream/video.mjpeg to /webcam/stream/video.mjpeg?123566798..."

Sorry, maybe I didn't explain that right. The URL only works without the extra bit. Looking at the Chrome inspector, I noticed that the OctoPrint site was adding it on when retrieving the stream

Yes, this is standard anti-caching behavior. You decorate the link with an unnecessary question mark and something random. The browser sees that it doesn't have this version and will then fetch it.

Okay, so your camera doesn't like the nonce. We may need to bring @foosel into this but I'll see if there's something in the config.yaml file which can toggle that off.

From this:

            var webcamImage = $("#webcam_image");
            var currentSrc = webcamImage.attr("src");

            // safari bug doesn't release the mjpeg stream, so we just set it up the once
            if (OctoPrint.coreui.browser.safari && currentSrc != undefined) {
                return;
            }

            var newSrc = self.settings.webcam_streamUrl();
            if (currentSrc != newSrc) {
                if (newSrc.lastIndexOf("?") > -1) {
                    newSrc += "&";
                } else {
                    newSrc += "?";
                }
                newSrc += new Date().getTime();

                self.webcamLoaded(false);
                self.webcamError(false);
                webcamImage.attr("src", newSrc);
            }

So here's where the nonce is being added in an attempt to prevent the browser from using a cached version. Perhaps in your case you'd need...

            if currentSrc != undefined:
                return;

...added before the Safari test.

Shouldn't that nonce contain a paramater name to prevent querystring parsers from having issues? For example 'nonce_ts={timestamp here}'? I'm guessing the streaming API can contain parameters, tries to parse the querystring, and fails because the querystring isn't formatted properly.

@camander321, can you see if this url works in your browser:

http://192.168.1.21:8080/stream/video.mjpeg?nonce=12345

I think you're onto something. If this works then there might be a one-size-fits-all-PR for this.

it really doesnt like any queries in the url at all. adding anything gives a 404

The nonce was 100% the issue! I used the Resource Override Chrome extension to strip off the nonce and its working perfectly now! Thanks for the help. You think this is worth opening up a Github issue for?

That's hard to say. Honestly, the webcam stuff is an add-on of the OctoPi image in a way and yet the nonce code is from OctoPrint. It might be a nice feature request to have this optional within the config.yaml, methinks.

What rule(s) did you add? I'm having the same problem.

Edit: Never mind. I solved it. How I solved it at: Webcam works when testing, but not in Control tab

Sorry for reopening the thread, but I have faced this problem a few days ago, and after some tries, I think I found a successful solution not involving chrome addons. Looking into octoprint source code I found the file control.js (in my case located in "~/oprint/lib/python2.7/site-packages/octoprint/static/js/app/viewmodels" adds the timestamp to the url of the stream.

I have commented a few lines and it is working without the Chrome Extension. The lines I have to comment (with // at the beginning) are

            if (newSrc.lastIndexOf("?") > -1) {
                newSrc += "&";
            } else {
                newSrc += "?";
            }
            newSrc += new Date().getTime();

In addition, the URL I have had to paste in octoprint it the complete one,in my case http://192.168.1.32:8080/stream/video.mjpeg

With this, it works on any browser, without any extension.

I hope it works for you too! Let me know

3 Likes