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
Problem solving templates for subsequence problems in dynamic programming
上线1周,B.Protocal已有7000ETH资产!
APP 莫名崩溃,开始以为是 Header 中 name 大小写的锅,最后发现原来是容器的错!
信息安全课程设计第一周任务(7条指令的分析)
Test comparison of three domestic cloud databases
Solve the problem that the value of new date() of JS in IE and Firefox is invalid date and Nan Nan
非阻塞的无界线程安全队列 —— ConcurrentLinkedQueue
LeetCode 45 跳跃游戏II
Using annotation + interceptor to implement asynchronous execution
JVM真香系列:轻松理解class文件到虚拟机(下)
The interface testing tool eolinker makes post request
梁老师小课堂|谈谈模板方法模式
非阻塞的无界线程安全队列 —— ConcurrentLinkedQueue
AQS 都看完了,Condition 原理可不能少!
ITerm2 配置和美化
Iterm2 configuration and beautification
centos7下安装iperf时出现 make: *** No targets specified and no makefile found. Stop.的解决方案
当我们聊数据质量的时候,我们在聊些什么?
综合架构的简述







