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,再也不用担心对不上日志了!

JVM Zhenxiang series: easy understanding of class files to virtual machines (Part 2)

Web上的分享(Share)API

. net core cross platform resource monitoring library and dotnet tool

实验一作业

Swagger介绍和应用

Leetcode-15: sum of three numbers

你有没有想过为什么交易和退款要拆开不同的表

Programmers should know the URI, a comprehensive understanding of the article

Factory pattern pattern pattern (simple factory, factory method, abstract factory pattern)
随机推荐
CMS garbage collector
Flink's datasource Trilogy 3: customization
Using annotation + interceptor to implement asynchronous execution
代码保存
一堆代码忘了缩进?快捷方式教你无忧无虑!
当我们聊数据质量的时候,我们在聊些什么?
服务器性能监控神器nmon使用介绍
程序员都应该知道的URI,一文帮你全面了解
对象
Solve the problem that the value of new date() of JS in IE and Firefox is invalid date and Nan Nan
大数据岗位基础要求有哪些?
Looking for a small immutable dictionary with better performance
第五章编程
Decorator (2)
centos7下安装iperf时出现 make: *** No targets specified and no makefile found. Stop.的解决方案
通过canvas获取视频第一帧封面图
第五章
Nodejs中request出现ESOCKETTIMEDOUT解决方案
LeetCode-15:三数之和
老大问我:“建表为啥还设置个自增 id ?用流水号当主键不正好么?”