Video to canvas demo

1D 2d canvas test

by Julien Etienne

JavaScript

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

document.body.appendChild(video);
document.body.appendChild(c);

video.addEventListener('loadeddata', function() {
  c.width = video.videoWidth;
  c.height = video.videoHeight;
}, false);

video.preload = 'auto';
video.src = 'https://media.w3.org/2010/05/sintel/trailer.mp4';
video.controls = true;

var draw = () => {
  ctx.drawImage(video, -(c.width / 2), 0, c.width * 2, c.height);
  //edit the image here
	requestAnimationFrame(draw);
};

requestAnimationFrame(draw);