Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

draw on canvas from video element js

var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var video = document.getElementById('video');

// set canvas size = video size when known
video.addEventListener('loadedmetadata', function() {
  canvas.width = video.videoWidth;
  canvas.height = video.videoHeight;
});

video.addEventListener('play', function() {
  var $this = this; //cache
  (function loop() {
    if (!$this.paused && !$this.ended) {
      ctx.drawImage($this, 0, 0);
      setTimeout(loop, 1000 / 30); // drawing at 30fps
    }
  })();
}, 0);
Comment

PREVIOUS NEXT
Code Example
Javascript :: .filter js 
Javascript :: node js http request 
Javascript :: loop through dom elements javascript 
Javascript :: how to load existing json data in nuxt 
Javascript :: router.push in vue 3 
Javascript :: how to get folder names with fs 
Javascript :: capitalize a string javascript 
Javascript :: how to change background color on scroll 
Javascript :: how to add youtube videos to react app 
Javascript :: get value for radio button in jquery label 
Javascript :: using .env in cra 
Javascript :: image preview 
Javascript :: convert date and time into epoch javascript 
Javascript :: js + before variable 
Javascript :: javascript insert element after 
Javascript :: js json data undefined 
Javascript :: reactjs cut part of string 
Javascript :: jquery convert time to 1day 2 minutes 4 seconds 
Javascript :: change text size according to screen react native 
Javascript :: complete math objects in javascript 
Javascript :: select react hook form yup validation 
Javascript :: react native only 1 corner rounded 
Javascript :: vue get if checkbox is checked 
Javascript :: Create MD5 hash with Node.js 
Javascript :: npm run js file from command line 
Javascript :: convert string to uppercase 
Javascript :: javascript list has item 
Javascript :: add checkbox dynamically in javascript 
Javascript :: array of images javascript 
Javascript :: gql TypeError: Object(...) is not a function 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =