Git Product home page Git Product logo

simplewebcamjs's Introduction

SimpleWebcamJs

A simple webcam video and snapshot tool using HTML, Javascript. Works on all browsers. Displays both the video and consecutive image snapshots in the browser screen.

Use it to place a video and camera snaps on your webpage, in your program, or even use it for a home webcam.

Setting it up

Setup is simple. Create the container.

<div id="scjs">
  <video id="scjs__video"></video>
  <div id="scjs__play">
    <canvas id="scjs__image"></canvas>
  </div>
  <div id="scjs__forward"><input type="button" id="scjs__button" value="Play"></div>
</div>

Place scjs.js before the closing </body> tag to include the bulk of the code.

<script src="scjs.js"></script>

And change the parameters...

<script language="Javascript">
  var __cfg = {
    video__width  : 200,
    video__height : 200,
    image__width  : 200,
    image__height : 200
  };
</script>

The code

The main access to video streaming media is __scjs__forward__media() and is accessed when you press the play button.

function __scjs__forward__media() // IO setup
{
  __vars = __cfg;
  navigator.mediaDevices.getUserMedia(
    {
      video:
      {
        width  : __vars.video__width,
        height : __vars.video__height
      }
    }
  )
  .then  ( __scjs__stream )
  .catch ( __scjs__stream__error );
}

The built in functions will run __scjs__stream continually unless an error is intercepted.

function __scjs__stream ( __IOdata ) // IO video streaming
{
  var video = document.querySelector( 'video' );
  video.srcObject = __IOdata;
  video.onloadedmetadata = function(e)
  {
    video.play();
  };
}

Once the play button fires, our intervals are set up in __scjs__forward

document.getElementById( "scjs__button" )
  .addEventListener( "click", __scjs__forward );
  
function __scjs__forward( e ) // setup intervals
{
  for ( let interval of __scjs__fwdintervals )
    clearInterval( interval.id );

  __scjs__forward__on = __scjs__forward__on ? 0 : 1;

  for ( let interval of __scjs__fwdintervals )
  {
    interval.fn();
    interval.id = setInterval( interval.fn, interval.time );
  }
}

And that's all there is to it.

simplewebcamjs's People

Contributors

backwardmachine avatar

Stargazers

 avatar

Watchers

 avatar

simplewebcamjs's Issues

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.