W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <p>要使用的视频:</p> <video id="video1" controls width="270" autoplay> <source src="/example/html5/mov_bbb.mp4" type='video/mp4'> <source src="/example/html5/mov_bbb.ogg" type='video/ogg'> <source src="/example/html5/mov_bbb.webm" type='video/webm'> </video> <p>画布(每 20 毫秒,代码就会绘制视频的当前帧):</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,0,0,270,135)},20);},false); v.addEventListener('pause',function() {window.clearInterval(i);},false); v.addEventListener('ended',function() {clearInterval(i);},false); </script> </body> </html>