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);
// Video to picture
canvas.toDataURL('image/png')
document.body.removeChild(video);
}
video.src = URL.createObjectURL(file.files[0]); // file Local files
document.body.appendChild(video);
// Get the video with equal scale width and height
function getVideoSize(maxWidth, width, height) {
if(maxWidth >= width) {
return {
width,
height
}
} else {
return {
width: maxWidth,
height: Math.floor(maxWidth / width * height)
}
}
}
当前位置:网站首页>Get the first cover image of video through canvas
Get the first cover image of video through canvas
2020-11-08 23:46:00 【action】
版权声明
本文为[action]所创,转载请带上原文链接,感谢
边栏推荐
- How to deploy pytorch lightning model to production
- Programmers should know the URI, a comprehensive understanding of the article
- 代码保存
- 非阻塞的无界线程安全队列 —— ConcurrentLinkedQueue
- Solve the problem that the value of new date() of JS in IE and Firefox is invalid date and Nan Nan
- LeetCode-15:三数之和
- APP 莫名崩溃,开始以为是 Header 中 name 大小写的锅,最后发现原来是容器的错!
- Dynamic planning
- Aprelu: cross border application, adaptive relu | IEEE tie 2020 for machine fault detection
- CMS垃圾收集器
猜你喜欢
How does semaphore, a thread synchronization tool that uses an up counter, look like?
Core knowledge of C + + 11-17 template (2) -- class template
200 programmers interview experience, all here
How to analyze Android anr problems
非阻塞的无界线程安全队列 —— ConcurrentLinkedQueue
程序员都应该知道的URI,一文帮你全面了解
C / C + + Programming Notes: pointer! Understand pointer from memory, let you understand pointer completely
First development of STC to stm32
选择API管理平台之前要考虑的5个因素
数据库设计:范式与反范式
随机推荐
程序员都应该知道的URI,一文帮你全面了解
APReLU:跨界应用,用于机器故障检测的自适应ReLU | IEEE TIE 2020
Constructors and prototypes
SQL语句的执行
JVM Zhenxiang series: easy understanding of class files to virtual machines (Part 2)
A few lines of code can easily transfer traceid across systems, so you don't have to worry about losing the log!
大数据岗位基础要求有哪些?
动态规划之子序列问题解题模板
C++邻接矩阵
Fiddler无法正常抓取谷歌等浏览器的请求_解决方案
基于链表的有界阻塞队列 —— LinkedBlockingQueue
理论与实践相结合彻底理解CORS
The interface testing tool eolinker makes post request
装饰器(二)
VIM 入门手册, (VS Code)
salesforce零基础学习(九十八)Salesforce Connect & External Object
centos7下安装iperf时出现 make: *** No targets specified and no makefile found. Stop.的解决方案
文件拷贝的实现
What courses will AI programming learn?
JVM真香系列:轻松理解class文件到虚拟机(下)