let video = document.createElement('video');
video.style="width:0;height:0;position:fixed;right:-100%;"
video.muted = 'muted';
video.autoplay = 'autoplay';
video.onloadeddata = function() {
let { width, height } = getVideoSize(120, this.videoWidth, this.videoHeight);
let canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
canvas.getContext('2d').drawImage(this, 0, 0, width, height);
// 视频转换为图片
canvas.toDataURL('image/png')
document.body.removeChild(video);
}
video.src = URL.createObjectURL(file.files[0]); // file本地文件
document.body.appendChild(video);
// 获取视频等比缩放宽高
function getVideoSize(maxWidth, width, height) {
if(maxWidth >= width) {
return {
width,
height
}
} else {
return {
width: maxWidth,
height: Math.floor(maxWidth / width * height)
}
}
}
当前位置:网站首页>通过canvas获取视频第一帧封面图
通过canvas获取视频第一帧封面图
2020-11-08 23:46:00 【action】
版权声明
本文为[action]所创,转载请带上原文链接,感谢
https://segmentfault.com/a/1190000037765094
边栏推荐
- Dynamic query processing method of stored procedure
- Newbe.ObjectVisitor Example 1
- C/C++学习日记:原码、反码和补码
- The road of cloud computing - going to sea - small goal: Hello world from. Net 5.0 on AWS
- Come and have a look! What is the relationship between AQS and countdownlatch?
- Five factors to consider before choosing API management platform
- 实现图片的复制
- LeetCode-11:盛水最多的容器
- Python的特性与搭建环境
- iptables从入门到掌握
猜你喜欢
随机推荐
云计算之路-出海记-小目标:Hello World from .NET 5.0 on AWS
Database design: paradigms and anti paradigms
Dynamic planning
快来看看!AQS 和 CountDownLatch 有怎么样的关系?
Factory Pattern模式(简单工厂、工厂方法、抽象工厂模式)
你有没有想过为什么交易和退款要拆开不同的表
【云服务】阿里云服务器ECS实例规格那么多,如何选型?最佳实践说明
寻找性能更优秀的动态 Getter 和 Setter 方案
Newbe.ObjectVisitor Example 1
Fiddler无法正常抓取谷歌等浏览器的请求_解决方案
npm install 无响应解决方案
Dynamic ReLU:微软推出提点神器,可能是最好的ReLU改进 | ECCV 2020
Flink的DataSource三部曲之三:自定义
数组初相识
Dynamic query processing method of stored procedure
使用容器存储表格数据
API生命周期的5个阶段
Countdownlatch explodes instantly! Based on AQS, why can cyclicbarrier be so popular?
代码保存
如何将 PyTorch Lightning 模型部署到生产中






