Display video inside HTML5 canvas


You can try the following code snippet to display video inside HTML5 canvas.

var canvas1 = document.getElementById('canvas');
var context = canvas1.getContext('2d');
var video = document.getElementById('video');
video.addEventListener('play', function () {
   var $this = this;
   (function loop() {
      if (!$this.paused && !$this.ended) {
         context.drawImage($this, 0, 0);
         setTimeout(loop, 1000 / 30);
      }
   })();
}, 0);

Updated on: 30-Jul-2019

301 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements