Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <body> <p>Video to use:</p> <video id="video1" controls width="270" autoplay> <source src="mov_bbb.mp4" type='video/mp4'> <source src="mov_bbb.ogg" type='video/ogg'> <source src="mov_bbb.webm" type='video/webm'> </video> <p>Canvas (the code draws the current frame of the video every 20 millisecond):</p> <canvas id="myCanvas" width="270" height="135" style="border:1px solid #d3d3d3;"> Your browser does not support the HTML5 canvas tag.</canvas> <script> var v = document.getElementById("video1"); var c = document.getElementById("myCanvas"); ctx = c.getContext("2d"); v.addEventListener("play", function() {var i = window.setInterval(function() {ctx.drawImage(v,5,5,260,125)},20);}, false); v.addEventListener("pause", function() {window.clearInterval(i);}, false); v.addEventListener("ended", function() {clearInterval(i);}, false); </script> </body> <!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryhtml5_canvas_drawimage_video by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 08:31:44 GMT --> </html>
Result:
Try it Yourself - © w3schools.com