Skip to content

Instantly share code, notes, and snippets.

@Fanckler
Created March 31, 2018 15:35
Show Gist options
  • Save Fanckler/02531645af3dfb6d52eb4ba750984c47 to your computer and use it in GitHub Desktop.
Save Fanckler/02531645af3dfb6d52eb4ba750984c47 to your computer and use it in GitHub Desktop.
draw video to canvas
//video canvas
var canvas = document.getElementById('canV');
var ctx = canvas.getContext('2d');
var video = document.createElement('video');
video.src = '../video/product.mp4';
video.addEventListener('loadeddata', function() {
video.play(); // start playing
update(); //Start rendering
});
function update() {
ctx.drawImage(video,0,0,850,850);
requestAnimationFrame(update); // wait for the browser to be ready to present another animation fram.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment