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]所创,转载请带上原文链接,感谢
边栏推荐
- 平台商业化能力的另一种表现形式SAAS
- 程序员都应该知道的URI,一文帮你全面了解
- 云计算之路-出海记-小目标:Hello World from .NET 5.0 on AWS
- Are there many Python application scenarios?
- LeetCode-11:盛水最多的容器
- 大数据软件学习入门技巧
- 使用递增计数器的线程同步工具 —— 信号量,它的原理是什么样子的?
- 综合架构的简述
- Realization of file copy
- Have you ever thought about why the transaction and refund have to be split into different tables
猜你喜欢
随机推荐
Why need to use API management platform
Python features and building environment
接口测试工具Eolinker进行post请求
一堆代码忘了缩进?快捷方式教你无忧无虑!
200 programmers interview experience, all here
程序员都应该知道的URI,一文帮你全面了解
SAP S/4HANA 2020安装实录
Decorator (2)
leetcode之反转字符串中的元音字母
平台商业化能力的另一种表现形式SAAS
Problem solving templates for subsequence problems in dynamic programming
A few lines of code can easily transfer traceid across systems, so you don't have to worry about losing the log!
用两个栈实现队列
几行代码轻松实现跨系统传递 traceId,再也不用担心对不上日志了!
解决IE、firefox浏览器下JS的new Date()的值为Invalid Date、NaN-NaN的问题
Aprelu: cross border application, adaptive relu | IEEE tie 2020 for machine fault detection
LeetCode-15:三数之和
经典动态规划:最长公共子序列
服务器性能监控神器nmon使用介绍
Constructors and prototypes