html5播放视频且动态截图实现步骤与代码(支持safari其他未测试)
暂不支持chrom 。支持safari .其他未测试
先引用 jquery 地址。选用新浪的
<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.6/jquery.js"></script>
加一个video标签
<video id="video" controls="controls">
<source src="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="http://lib.sinaapp.com/js/jquery/1.6/jquery.js"></script>
加一个video标签
复制代码
代码如下:<video id="video" controls="controls">
<source src="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>
效果图就不贴了。
最后更新于 2022-11-01 11:23:38 并被添加「html5播放视频 动态截图 」标签,已有 位童鞋阅读过。
本站使用「署名 4.0 国际」创作共享协议,可自由转载、引用,但需署名作者且注明文章出处
相关文章
- C语言自动关机程序(C语言关机程序代码)
- websocket+sockjs+stompjs详解及实例代码
- 详解HTML5 canvas绘图基本使用方法
- WordPress Shortcode(简码)介绍及使用详解
- win10+anaconda安装yolov5的方法及问题解决方案