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
边栏推荐
猜你喜欢
CMS垃圾收集器
The interface testing tool eolinker makes post request
API生命周期的5个阶段
Come and have a look! What is the relationship between AQS and countdownlatch?
200人的程序员面试经验,都在这里了
Table join
Newbe.ObjectVisitor Example 1
VIM 入门手册, (VS Code)
Flink's datasource Trilogy 3: customization
Iptables from introduction to mastery
随机推荐
CountDownLatch 瞬间炸裂!同基于 AQS,凭什么 CyclicBarrier 可以这么秀?
单例模式的五种设计方案
Database design: paradigms and anti paradigms
Tasks of the first week of information security curriculum design (analysis of 7 instructions)
Mycat搭建
SQL语句的执行
Classical dynamic programming: longest common subsequence
如何让脚本同时兼容Python2和Python3?
寻找性能更优秀的不可变小字典
老大问我:“建表为啥还设置个自增 id ?用流水号当主键不正好么?”
综合架构的简述
使用Fastai开发和部署图像分类器应用
LeetCode 45 跳跃游戏II
解决IE、firefox浏览器下JS的new Date()的值为Invalid Date、NaN-NaN的问题
Flink's datasource Trilogy 3: customization
计算机网络 应用层
. net core cross platform resource monitoring library and dotnet tool
使用Fastai开发和部署图像分类器应用
实现图片的复制
上线1周,B.Protocal已有7000ETH资产!