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);
// 视频转换为图片
canvas.toDataURL('image/png')
document.body.removeChild(video);
}
video.src = URL.createObjectURL(file.files[0]); // file本地文件
document.body.appendChild(video);
// 获取视频等比缩放宽高
function getVideoSize(maxWidth, width, height) {
if(maxWidth >= width) {
return {
width,
height
}
} else {
return {
width: maxWidth,
height: Math.floor(maxWidth / width * height)
}
}
}
当前位置:网站首页>通过canvas获取视频第一帧封面图
通过canvas获取视频第一帧封面图
2020-11-08 23:46:00 【action】
版权声明
本文为[action]所创,转载请带上原文链接,感谢
https://segmentfault.com/a/1190000037765094
边栏推荐
- 选择排序
- Using annotation + interceptor to implement asynchronous execution
- To introduce to you, this is my flow chart software—— draw.io
- Introduction and application of swagger
- Queue with two stacks
- AI人工智能编程培训学什么课程?
- C/C++编程笔记:指针篇!从内存理解指针,让你完全搞懂指针
- Computer network application layer
- How to deploy pytorch lightning model to production
- Newbe.ObjectVisitor Example 1
猜你喜欢

JVM真香系列:轻松理解class文件到虚拟机(上)

iptables从入门到掌握

Decorator (2)
![[200 interview experience], programmer interview, common interview questions analysis](/img/fb/625e17f83f6be064f7387e78ec082a.jpg)
[200 interview experience], programmer interview, common interview questions analysis

Brief introduction of Integrated Architecture

给大家介绍下,这是我的流程图软件 —— draw.io

APP 莫名崩溃,开始以为是 Header 中 name 大小写的锅,最后发现原来是容器的错!

Copy the picture

Experiment 1 assignment

Factory Pattern模式(简单工厂、工厂方法、抽象工厂模式)
随机推荐
200人的程序员面试经验,都在这里了
【云服务】阿里云服务器ECS实例规格那么多,如何选型?最佳实践说明
Creating a text cloud or label cloud in Python
API生命周期的5个阶段
Brief introduction of Integrated Architecture
JVM真香系列:轻松理解class文件到虚拟机(上)
Using containers to store table data
AQS 都看完了,Condition 原理可不能少!
为什么需要使用API管理平台
The minimum insertion times of palindrome
Solve the failure of go get download package
CMS garbage collector
What are the basic requirements for big data posts?
Programmers should know the URI, a comprehensive understanding of the article
VIM Introduction Manual, (vs Code)
都说程序员钱多空少,程序员真的忙到没时间回信息了吗?
How to analyze Android anr problems
Classical dynamic programming: longest common subsequence
Array acquaintance
To introduce to you, this is my flow chart software—— draw.io