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
边栏推荐
- LeetCode-11:盛水最多的容器
- 实验一作业
- CountDownLatch 瞬间炸裂!同基于 AQS,凭什么 CyclicBarrier 可以这么秀?
- 快来看看!AQS 和 CountDownLatch 有怎么样的关系?
- 存储过程动态查询处理方法
- 国内三大云数据库测试对比
- Tasks of the first week of information security curriculum design (analysis of 7 instructions)
- Django's simple user system (3)
- Suffix expression to infix expression
- 老大问我:“建表为啥还设置个自增 id ?用流水号当主键不正好么?”
猜你喜欢

Database design: paradigms and anti paradigms

装饰器(一)

教你如何 分析 Android ANR 问题

使用递增计数器的线程同步工具 —— 信号量,它的原理是什么样子的?

Come and have a look! What is the relationship between AQS and countdownlatch?

Suffix expression to infix expression

表连接

Octave basic syntax

C/C++学习日记:原码、反码和补码

Creating a text cloud or label cloud in Python
随机推荐
Python的特性与搭建环境
Python features and building environment
构造函数和原型
实验一作业
Fiddler无法正常抓取谷歌等浏览器的请求_解决方案
Development and deployment of image classifier application with fastai
计算机网络 应用层
STC转STM32第一次开发
文件拷贝的实现
快来看看!AQS 和 CountDownLatch 有怎么样的关系?
Esockettimeout solution in request in nodejs
To introduce to you, this is my flow chart software—— draw.io
Dynamic query processing method of stored procedure
教你如何 分析 Android ANR 问题
Part 1 - Chapter 2 pointer operation
上线1周,B.Protocal已有7000ETH资产!
选择排序
getBytes之 LengthFieldBasedFrameDecoder服务端解析
实现图片的复制
Why need to use API management platform