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]所创,转载请带上原文链接,感谢
边栏推荐
猜你喜欢
Looking for better dynamic getter and setter solutions
表连接
Fiddler无法正常抓取谷歌等浏览器的请求_解决方案
Newbe.ObjectVisitor 样例 1
AQS 都看完了,Condition 原理可不能少!
Are there many Python application scenarios?
Newbe.ObjectVisitor Example 1
服务器性能监控神器nmon使用介绍
centos7下安装iperf时出现 make: *** No targets specified and no makefile found. Stop.的解决方案
老大问我:“建表为啥还设置个自增 id ?用流水号当主键不正好么?”
随机推荐
leetcode之反转字符串中的元音字母
装饰器(一)
AQS 都看完了,Condition 原理可不能少!
LeetCode 45 跳跃游戏II
Installation record of SAP s / 4hana 2020
Using annotation + interceptor to implement asynchronous execution
对象
基于链表的有界阻塞队列 —— LinkedBlockingQueue
[200 interview experience], programmer interview, common interview questions analysis
动态规划之子序列问题解题模板
Looking for better dynamic getter and setter solutions
你有没有想过为什么交易和退款要拆开不同的表
Fiddler can't grab requests from browsers like Google_ Solution
接口测试工具Eolinker进行post请求
经典动态规划:最长公共子序列
Python的特性与搭建环境
使用递增计数器的线程同步工具 —— 信号量,它的原理是什么样子的?
Why need to use API management platform
How to deploy pytorch lightning model to production
VIM Introduction Manual, (vs Code)