Git Product home page Git Product logo

webcam-easy's Introduction

Webcam Easy JS

This is a javascript library for accessing webcam stream and taking photos.

You can easily add it as a module to your own app.

  • Streaming webcam on desktop computer or mobile
  • Switch back or front cameras on mobile
  • Take pictures and be able to download.

Live Demo

https://bensonruan.com/how-to-access-webcam-and-take-photo-with-javascript/

webcam-easy-demo

Installation

Use Git Clone

git https://github.com/bensonruan/webcam-easy.git

OR Use NPM

NPM

npm install webcam-easy

Usage

1. Include script tag in html

<script type="text/javascript" src="https://unpkg.com/webcam-easy/dist/webcam-easy.min.js"></script>
or Import into javascript
import Webcam from 'webcam-easy';

2. Place elements in HTML

<video id="webcam" autoplay playsinline width="640" height="480"></video>
<canvas id="canvas" class="d-none"></canvas>
<audio id="snapSound" src="audio/snap.wav" preload = "auto"></audio>

3. Call constructor in javascript

const webcamElement = document.getElementById('webcam');
const canvasElement = document.getElementById('canvas');
const snapSoundElement = document.getElementById('snapSound');
const webcam = new Webcam(webcamElement, 'user', canvasElement, snapSoundElement);

4. Start Webcam

webcam.start()
   .then(result =>{
      console.log("webcam started");
   })
   .catch(err => {
       console.log(err);
   });

5. Take Photo

var picture = webcam.snap();

6. Stop Webcam

webcam.stop();

Functions

  • start(startStream) : start streaming webcam

    • get permission from user
    • get all video input devices info
    • select camera based on facingMode
    • start stream

    startStream is optional parameter, default value is true

  • stop() : stop streaming webcam

  • stream() : start streaming webcam to video element

  • snap() : take photo from webcam

  • flip() : change Facing mode and selected camera

Properties

  • facingMode : 'user' or 'enviroment'
  • webcamList : all available camera device
  • webcamCount : number of available camera device

Support me

ko-fi

webcam-easy's People

Contributors

bensonruan avatar dependabot[bot] avatar rilla avatar sgoerzen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webcam-easy's Issues

why in my code "environment" parameter doesn't work to solve reverse problems

<script type="text/javascript" src="https://unpkg.com/webcam-easy/dist/webcam-easy.min.js"></script> <script> window.addEventListener('load', function() { //js代码 const webcamElement = document.getElementById('webcam'); const canvasElement = document.getElementById('canvas'); //const snapSoundElement = document.getElementById('snapSound'); const webcam = new Webcam(webcamElement, 'environment', canvasElement); webcam.flip(); webcam.start() .then(result =>{ console.log("webcam started"); }) .catch(err => { console.log(err); }); }); </script>

the code always streaming video reversed, i tried webcam.flip() or set the 'environment' parameter to webcam but doesn't work:
const webcam = new Webcam(webcamElement, 'environment', canvasElement);

is anybody solved this problem?
2

Changing Aspect Ratio?

Is there a way to change the aspect ratio of the image? Since I need the image to be 1x1 (480x480px).

Letters are reversed

Hi,
Please help me, how to fix a letters are reversed bug after snap a picture.
Thank you.

App freezes after clicking picture in Android

Hey, your library is really useful for my project - Thank you so much.

But after the latest chrome update (with the latest Chrome version (90.0.4430.91), the app freezes after clicking the photo in Android, not able to use it. The library was working fine before the update.

Can you please check on it?

Thanks!

camera focus option

is it possible to get a camera focus option? the images seem blurred and out of focus

Custom file type

Is possible to choose file type? Right now method snap return png img, but I need it as jpg.

NotReadableError: Could not start video source

Hi,
I'm having trouble using the library for some Android devices, and it throws NotReadableError: Could not start video source error message in Chrome even though all permissions are provided.

Chrome ver. 92.0.4515
Samsung Note 10+
Screenshot_20210804-182100_Chrome

Thank you.

Android webview front camera

Hi,

I tried to to use the library in Android webview. Despite using 'environment' facing mode it is showing front camera instead of rear. Did someone solve this issue?

Thanks,
Mark

Can't access to webcam-easy with localhost

Hi, today I encounter a CORS issue when using webcam-easy.

I use the CDN <script type="text/javascript" src="https://unpkg.com/webcam-easy/dist/webcam-easy.min.js"></script>.

It worked great yesterday, but today I got CORS issue.

I was developing on MacBook Pro/iPhone 12 iOS 15.4.1 with the latest Chrome installed.

Thanks.

How do I switch cameras?

If I have multiple webcams/video inputs, how do I specify which one to use? Right now, it defaults to the first one found.

Calling webcam functions results in multiple browser prompts for access in chrome

Calling webcam.start with default args of stream = true, the stream call results in two separate prompts to the user to allow access to the webcam in Chrome. Is there a way to request permissions from the user only once for the lifetime of the webcam object? This is the result of the navigator.mediaDevices.getUserMedia(this.getMediaConstraints()) call in both functions. In the stream function the this._streamList should be checked, and if not empty, simply use the existing stream object.

overflow-y

Hello,

I use the camera like a popup. But after closing the camera I lost the scrollbar.

There a 2 $('body').css('overflow-y','hidden'); but no restores.

And a $('body').css('overflow-y','visible'); in cameraStopped() or ('#exit-app') dosn,t restore the scrollbar.

But Thanks for the app

save to base64

Hello,

thank you - good work! i like it very much!
is it possible to get the picture as a base64 encoded variable, f.e. saving the picture to a database.

Best Regard,
Martin

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.