canvas实现视频截图
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了canvas实现视频截图相关的知识,希望对你有一定的参考价值。
截取视频当前播放画面,直接上源码。
<body>
<div class="container">
<video id="test" width="500" height="400" >
<source src="test.mp4" type="video/mp4">
</video>
</div>
<canvas height="400" width="500" id="canvas2" style="border:1px solid #000;margin: 50px;"></canvas>
<canvas height="400" width="500" id="canvas1" style="border:1px solid #000;margin: 50px;display: none;"></canvas>
<button type="button" onclick="drawImg()">click</button>
<script>
var video = document.getElementById(‘test‘);
var canvas1 = document.getElementById(‘canvas1‘);
var canvas2 = document.getElementById(‘canvas2‘);
var context1 = canvas1.getContext(‘2d‘);
var context2 = canvas2.getContext(‘2d‘);
function drawVideo() {
context1.drawImage(video,0,0,video.width,video.height);
}
function drawImg() {
context2.drawImage(canvas1,0,0,canvas1.width,canvas1.height)
}
video.play();
setInterval(drawVideo,100);
</script>
</body>
以上是关于canvas实现视频截图的主要内容,如果未能解决你的问题,请参考以下文章