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
边栏推荐
- Server side resolution of lengthfieldbasedframedecoder of GetBytes
- 【云服务】阿里云服务器ECS实例规格那么多,如何选型?最佳实践说明
- 200人的程序员面试经验,都在这里了
- Computer network application layer
- 表连接
- Looking for better dynamic getter and setter solutions
- LeetCode-15:三数之和
- 综合架构的简述
- 寻找性能更优秀的不可变小字典
- JVM Zhenxiang series: easy understanding of class files to virtual machines (Part 2)
猜你喜欢
存储过程动态查询处理方法
上线1周,B.Protocal已有7000ETH资产!
寻找性能更优秀的动态 Getter 和 Setter 方案
RabbitMQ快速入门详解
Using fastai to develop and deploy image classifier application
The road of cloud computing - going to sea - small goal: Hello world from. Net 5.0 on AWS
快来看看!AQS 和 CountDownLatch 有怎么样的关系?
Python应用场景多不多?
APP 莫名崩溃,开始以为是 Header 中 name 大小写的锅,最后发现原来是容器的错!
文件拷贝的实现
随机推荐
Django之简易用户系统(3)
Chapter five
Flink's datasource Trilogy 3: customization
JVM真香系列:轻松理解class文件到虚拟机(下)
VIM Introduction Manual, (vs Code)
200人的程序员面试经验,都在这里了
Python features and building environment
选择API管理平台之前要考虑的5个因素
Swagger介绍和应用
C / C + + learning diary: original code, inverse code and complement code
CountDownLatch 瞬间炸裂!同基于 AQS,凭什么 CyclicBarrier 可以这么秀?
Execution of SQL statement
存储过程动态查询处理方法
To introduce to you, this is my flow chart software—— draw.io
为什么需要使用API管理平台
第五章
Octave basic syntax
用两个栈实现队列
服务器性能监控神器nmon使用介绍
Infix expression to suffix expression