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]所创,转载请带上原文链接,感谢
边栏推荐
猜你喜欢

几行代码轻松实现跨系统传递 traceId,再也不用担心对不上日志了!

salesforce零基础学习(九十八)Salesforce Connect & External Object

梁老师小课堂|谈谈模板方法模式

How to analyze Android anr problems

Introduction to nmon

大数据软件学习入门技巧

Why need to use API management platform

Core knowledge of C + + 11-17 template (2) -- class template

Copy on write collection -- copyonwritearraylist

Are there many Python application scenarios?
随机推荐
Python features and building environment
用两个栈实现队列
几行代码轻松实现跨系统传递 traceId,再也不用担心对不上日志了!
Are there many Python application scenarios?
On buffer overflow
上线1周,B.Protocal已有7000ETH资产!
AQS 都看完了,Condition 原理可不能少!
数据库设计:范式与反范式
Octave basic syntax
Introduction skills of big data software learning
ITerm2 配置和美化
使用递增计数器的线程同步工具 —— 信号量,它的原理是什么样子的?
Salesforce connect & external object
Fiddler无法正常抓取谷歌等浏览器的请求_解决方案
JVM Zhenxiang series: easy understanding of class files to virtual machines (Part 2)
华为HCIA笔记
Mycat搭建
新手入坑指南:工作原因“重启”Deepin系统,发现真的香啊
Leetcode 45 jumping game II
链表