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]所创,转载请带上原文链接,感谢
边栏推荐
- Python应用场景多不多?
- Flink的DataSource三部曲之三:自定义
- Factory pattern pattern pattern (simple factory, factory method, abstract factory pattern)
- Newbe.ObjectVisitor 样例 1
- JVM Zhenxiang series: easy understanding of class files to virtual machines (Part 2)
- Brief introduction of Integrated Architecture
- 用两个栈实现队列
- [200 interview experience], programmer interview, common interview questions analysis
- LeetCode 45 跳跃游戏II
- Save code
猜你喜欢
上线1周,B.Protocal已有7000ETH资产!
Constructors and prototypes
STS安装
JVM真香系列:轻松理解class文件到虚拟机(下)
表连接
接口测试工具Eolinker进行post请求
Solve the problem that the value of new date() of JS in IE and Firefox is invalid date and Nan Nan
综合架构的简述
选择API管理平台之前要考虑的5个因素
Aprelu: cross border application, adaptive relu | IEEE tie 2020 for machine fault detection
随机推荐
Tasks of the first week of information security curriculum design (analysis of 7 instructions)
程序员都应该知道的URI,一文帮你全面了解
Dynamic planning
Factory pattern pattern pattern (simple factory, factory method, abstract factory pattern)
Programmers should know the URI, a comprehensive understanding of the article
STS安装
非阻塞的无界线程安全队列 —— ConcurrentLinkedQueue
Leetcode 45 jumping game II
CMS垃圾收集器
Octave基本语法
服务器性能监控神器nmon使用介绍
android开发中提示:requires permission android.permission write_settings解决方法
AQS 都看完了,Condition 原理可不能少!
APReLU:跨界应用,用于机器故障检测的自适应ReLU | IEEE TIE 2020
LeetCode 45 跳跃游戏II
Fiddler无法正常抓取谷歌等浏览器的请求_解决方案
实现图片的复制
Flink's datasource Trilogy 3: customization
上线1周,B.Protocal已有7000ETH资产!
centos7下安装iperf时出现 make: *** No targets specified and no makefile found. Stop.的解决方案