JS Get image directly from video stream as data url

HSchmale

How would I go directly from video capture to a data url in javascript? I want to display the image to the user as a resized version, but keep the full size image available. So, how would I do this?

var PhotoBooth = {
    onMediaStream: function(stream) {
        PhotoBooth.canvas = $('canvas')[0];
        PhotoBooth.context = PhotoBooth.canvas.getContext('2d');

        PhotoBooth.localVideo = $('video')[0];
        PhotoBooth.localVideo.src = window.URL.createObjectURL(stream);
    },
    noStream: function() {
        console.log('FAIL TO GET WEBCAM ACCESS');
    }
};

getUserMedia(
    {video: true},
    PhotoBooth.onMediaStream,
    PhotoBooth.noStream
);

This is how I am currently saving the image for upload:

PhotoBooth.context.drawImage(PhotoBooth.localVideo, 0, 0, 200, 150);
$('#preview').show();

Then I retrive the saved image like so:

var dataUrl = PhotoBooth.canvas.toDataURL();

I'd like to keep the canvas the same size it is by default, but keep the actual data. Basically, I want the canvas to show a re-sized version, but maintain the full size version.

jib

Here, canvas maintains the original 640x480 snapshot (use https fiddle for Chrome):

var start = () => navigator.mediaDevices.getUserMedia({ video: true })
  .then(stream => video.srcObject = stream)
  .catch(log);

var canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 480;

var snap = () => {
  canvas.getContext('2d').drawImage(video, 0, 0, 640, 480);
  preview.getContext('2d').drawImage(canvas, 0, 0, 160, 120);
}

var log = msg => div.innerHTML += "<br>" + msg;
<button onclick="start()">Start!</button>
<button onclick="snap()">Snap!</button><div id="div"></div>
<video id="video" width="160" height="120" autoplay></video>
<canvas id="preview" width="160" height="120"></canvas>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Is it possible now to use GetUserMedia API to read video stream from web camera and send it directly to server for further broadcasting?

From Dev

GET YouTube Video URL - Data API 3.0

From Dev

how to deliver video-streaming from image stream in c#

From Dev

How to create Stream object directly from Image stored in Data Table?

From Dev

Get streaming URL from any YouTube video

From Dev

Get an image from the video

From Dev

Get Dailymotion video desctiption from URL

From Dev

Xuggler get jpeg image from rtsp stream

From Dev

Get data directly from nested array in AngulaJS

From Dev

How to Stream Video from Http or RTSP Url in android

From Dev

is any way to get image data from canvas, drawed from remote video?

From Dev

get image from uploaded video codeigniter

From Dev

How to extract('demux') from 'mp4' video to get the encoded data(or elementary stream) using ffmpeg?

From Dev

Get image dimensions directly from URL in C#

From Dev

Get Bitmap image from Url

From Dev

get video duration from URL in android app

From Dev

Is it possible now to use GetUserMedia API to read video stream from web camera and send it directly to server for further broadcasting?

From Dev

GET YouTube Video URL - Data API 3.0

From Dev

android URL stream cannot get whole data

From Dev

How to get video URL to download video from RTMP stream

From Dev

Get url from uploaded video on facebook

From Dev

Get data directly from nested array in AngulaJS

From Dev

Get / Make thumbnail image from video url getting in API response

From Dev

Trying to get image URL from meta data of custom post

From Dev

Stream YouTube video from extracted url

From Dev

How to get video file stream from embed url in c#

From Dev

Using Python how could I get still image from a certain point in video at a url?

From Dev

How to get active stream or video track (from quagga.js)?

From Dev

Import Video from URL and directly pass to visitor for download

Related Related

  1. 1

    Is it possible now to use GetUserMedia API to read video stream from web camera and send it directly to server for further broadcasting?

  2. 2

    GET YouTube Video URL - Data API 3.0

  3. 3

    how to deliver video-streaming from image stream in c#

  4. 4

    How to create Stream object directly from Image stored in Data Table?

  5. 5

    Get streaming URL from any YouTube video

  6. 6

    Get an image from the video

  7. 7

    Get Dailymotion video desctiption from URL

  8. 8

    Xuggler get jpeg image from rtsp stream

  9. 9

    Get data directly from nested array in AngulaJS

  10. 10

    How to Stream Video from Http or RTSP Url in android

  11. 11

    is any way to get image data from canvas, drawed from remote video?

  12. 12

    get image from uploaded video codeigniter

  13. 13

    How to extract('demux') from 'mp4' video to get the encoded data(or elementary stream) using ffmpeg?

  14. 14

    Get image dimensions directly from URL in C#

  15. 15

    Get Bitmap image from Url

  16. 16

    get video duration from URL in android app

  17. 17

    Is it possible now to use GetUserMedia API to read video stream from web camera and send it directly to server for further broadcasting?

  18. 18

    GET YouTube Video URL - Data API 3.0

  19. 19

    android URL stream cannot get whole data

  20. 20

    How to get video URL to download video from RTMP stream

  21. 21

    Get url from uploaded video on facebook

  22. 22

    Get data directly from nested array in AngulaJS

  23. 23

    Get / Make thumbnail image from video url getting in API response

  24. 24

    Trying to get image URL from meta data of custom post

  25. 25

    Stream YouTube video from extracted url

  26. 26

    How to get video file stream from embed url in c#

  27. 27

    Using Python how could I get still image from a certain point in video at a url?

  28. 28

    How to get active stream or video track (from quagga.js)?

  29. 29

    Import Video from URL and directly pass to visitor for download

HotTag

Archive