Html视频播放同时获取当前帧下的图片

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>W3CSchool Demo</title>
</head>
<body>
    <video id="video1" controls="" width="270" style="margin-top:15px;">
          <source src="demo/video1.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>
    <canvas id="myCanvas4" width="270" height="135" style="border:1px solid #d3d3d3; margin-top:15px;">
        Your browser does not support the HTML5 canvas tag.
    </canvas>
    <script>
        var v=document.getElementById("video1");
        var c=document.getElementById("myCanvas4");
        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>

参考W3CSchool:http://www.w3school.com.cn/tags/canvas_drawimage.asp

原文地址:https://www.cnblogs.com/ifindu-san/p/7112470.html