<body>
<video width="200" height="300" controls src="../lijiahui.mp4"></video>
<canvas style="border: solid; opacity: 0; position: absolute;z-index: -1;" width="200" height="300"></canvas>
<button>截图</button>
<button id="pause">暂停并截图</button>
<script type="text/javascript">
let drawing = document.querySelector("canvas");
let ctx = drawing.getContext('2d');
let btn = document.querySelector('button');
let video = document.querySelector('video');
let pauseBtn = document.querySelector('#pause');
btn.onclick = function() {
ctx.drawImage(video, 0, 0, 170, 300);
let img = document.createElement('img');
img.src = ctx.canvas.toDataURL();
console.log(img);
document.body.appendChild(img);
};
pauseBtn.onclick = function(){
video.pause();
ctx.drawImage(video, 100, 0, 170, 300);
let img = document.createElement('img');
img.src = ctx.canvas.toDataURL();
console.log(img);
document.body.appendChild(img);
}
video.onloadeddata = function() {
//这里是音乐加载完后做的事,但不到为毛写在这里不好使。
}
</script>
``
来找我玩啊
![在这里插入图片描述](/i/ll/?i=20200809103746791.jpg?,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3ByaW50Zl9oZWxsbw==,size_16,color_FFFFFF,t_70)
标签:一帧,img,截取,ctx,画布,let,querySelector,video,document
From: https://blog.51cto.com/u_15964288/6056542