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
边栏推荐
- Database design: paradigms and anti paradigms
- Programmers should know the URI, a comprehensive understanding of the article
- 动态规划答疑篇
- 新手入坑指南:工作原因“重启”Deepin系统,发现真的香啊
- 快来看看!AQS 和 CountDownLatch 有怎么样的关系?
- 200 programmers interview experience, all here
- 为什么需要使用API管理平台
- 非阻塞的无界线程安全队列 —— ConcurrentLinkedQueue
- How to analyze Android anr problems
- Django之简易用户系统(3)
猜你喜欢
随机推荐
Experiment 1 assignment
What courses will AI programming learn?
数组初相识
解决IE、firefox浏览器下JS的new Date()的值为Invalid Date、NaN-NaN的问题
ITerm2 配置和美化
新手入坑指南:工作原因“重启”Deepin系统,发现真的香啊
实验一作业
JVM真香系列:轻松理解class文件到虚拟机(下)
CMS垃圾收集器
[200 interview experience], programmer interview, common interview questions analysis
. net core cross platform resource monitoring library and dotnet tool
Mycat搭建
200 programmers interview experience, all here
c++11-17 模板核心知识(二)—— 类模板
Python的特性与搭建环境
How to make scripts compatible with both Python 2 and python 3?
[cloud service] there are so many ECS instances on alicloud server, how to select the type? Best practice note
Case analysis of entitycore framework
Why need to use API management platform
Solve the failure of go get download package








