html5播放视频且动态截图实现步骤与代码(支持safari其他未测试)
(编辑:jimmy 日期: 2024/12/26 浏览:3 次 )
暂不支持chrom 。支持safari .其他未测试
先引用 jquery 地址。选用新浪的
复制代码代码如下:
<script type="text/javascript" src="/UploadFiles/2021-03-30/jquery.js">
加一个video标签
复制代码代码如下:
<video id="video" controls="controls">
<source src="/UploadFiles/2021-03-30/1.mp4"></video>
然后js
复制代码代码如下:
<script type="text/javascript">
$().ready(function(){
var video, output;
var scale = 0.25;
var initialize = function() {
output = $("#output");
video = $("#video").get(0);
$("#capture").click(captureImage);
};
var captureImage = function() {
var canvas = document.createElement("canvas");
canvas.width = video.videoWidth * scale;
canvas.height = video.videoHeight * scale;
canvas.getContext('2d')
.drawImage(video, 0, 0, canvas.width, canvas.height);
var img = document.createElement("img");
img.src = canvas.toDataURL();
output.prepend(img);
};
$(initialize);
});
</script>
效果图就不贴了。
先引用 jquery 地址。选用新浪的
复制代码代码如下:
<script type="text/javascript" src="/UploadFiles/2021-03-30/jquery.js">
加一个video标签
复制代码代码如下:
<video id="video" controls="controls">
<source src="/UploadFiles/2021-03-30/1.mp4"></video>
然后js
复制代码代码如下:
<script type="text/javascript">
$().ready(function(){
var video, output;
var scale = 0.25;
var initialize = function() {
output = $("#output");
video = $("#video").get(0);
$("#capture").click(captureImage);
};
var captureImage = function() {
var canvas = document.createElement("canvas");
canvas.width = video.videoWidth * scale;
canvas.height = video.videoHeight * scale;
canvas.getContext('2d')
.drawImage(video, 0, 0, canvas.width, canvas.height);
var img = document.createElement("img");
img.src = canvas.toDataURL();
output.prepend(img);
};
$(initialize);
});
</script>
效果图就不贴了。
下一篇:html5中地理位置定位api接口开发应用小结