HTML-canvasVideo

HTML-canvasVideo

特定视频帧画框

<!DOCTYPE html>
<html lang="en">
<head>
  <style>
    body{background:black;color:#CCCCCC;}
    div{float:left;border:1px solid #444444;padding:10px;margin:10px;background:#3B3B3B;}
  </style>
</head>
<body onload="processor.doLoad()">
  <div style="display:none;">
    <video id="video" src="movie.mp4" controls="true" />
  </div>
  <div>
    <canvas id="c1" width="1680" height="640" />
 <script type="text/javascript">
  var fircanvas=document.getElementById("c1");
  var fircantxt=fircanvas.getContext("2d");
  var str="click to play the video!";
  
  fircantxt.beginPath();
  fircantxt.fillStyle="white";
  fircantxt.font="100px serif";
  fircantxt.fillText(str,200,200);
  fircantxt.closePath(); 
 </script>
  </div>
</body>
</html>
  <script type="text/javascript">
var btn = document.getElementById('c1');
var video = document.getElementById('video');
btn.addEventListener('click',function(){
  if(video.paused){
      video.play();
    }
  else{
      video.pause();
    }
 });
 
 var processor = {
      timerCallback: function() {
        if (this.video.paused || this.video.ended) {
          return;
        }
        this.computeFrame(2,200,200,300,350);
        var self = this;
        setTimeout(function () {
            self.timerCallback();
          }, 0);
      },
      doLoad: function() {
        this.video = document.getElementById("video");
        this.c1 = document.getElementById("c1");
        this.ctx1 = this.c1.getContext("2d");
        var self = this;
        this.video.addEventListener("play", function() {
            self.width = self.video.videoWidth;
            self.height = self.video.videoHeight;
   //console.log( self.width,self.height);
   self.c1.width = self.width;
   self.c1.height = self.height;
            self.timerCallback();
          }, false);
      },
      computeFrame: function(offset,upl,upr,downl,downr) {
  //console.log(Math.round(this.video.currentTime));
  this.ctx1.drawImage(this.video, 0, 0, this.width, this.height);
        if (Math.floor(this.video.currentTime) == offset) {
  this.ctx1.lineWidth=5;
  this.ctx1.strokeStyle = "rgba(255,0,0,1)";
        //this.ctx1.strokeRect(2*Math.round(Math.random()*10),Math.round(Math.random()*20),10*Math.round(Math.random()*10),20*Math.round(Math.random()*10));
  this.ctx1.strokeRect(upl,upr,downl,downr);
  }
        return;
      }
    };
   </script>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值