Code Monkey home page Code Monkey logo

Comments (1)

jhuckaby avatar jhuckaby commented on May 16, 2024

Hmm, well, you can improve the capture side of things, by triggering another snap() after each upload is complete. So instead of relying on timers on the client-side, the frequency of the image capture and upload is "as quickly as it can". The Webcam.upload() function actually accepts three arguments, the 3rd being a callback function that is fired when the upload is complete. So you can use that to trigger another snap(). Example:

Webcam.upload( data_uri, '/webcam/myscript.php', take_snapshot );

That will stream images to your server as quickly as it possibly can, without using timers. Now, on the server side, you should make sure to save your images to disk "atomically" (save temp file, then rename temp file over original), so when clients are viewing your images, you don't send any "half written" (i.e. corrupted) ones. Actually, I see you're using move_uploaded_file() -- I believe that is atomic.

Now, the problem really becomes how to "stream" the images to clients who are watching it. You could do the same sort of trick on the view side -- trigger an image reload after each load event is fired on the IMG object. Something like...

<img src="/webcam-img/webcam.jpg" onload="this.src='/webcam-img/webcam.jpg'+Math.random();"/>

This should work, but it will waste some bandwidth on the viewer's side, because the image will likely be able to refresh faster than you can upload it.

For something more like a true "video stream" I think you'd need Node.JS and Websockets.

Good luck!

from webcamjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.