当前位置: 首页 > news >正文

js截取video视频某一帧为图片

1.代码如下

<template><div class="box"><div class="video-box"><video controls ref="videoRef" preload="true"src="https://qt-minio.ictshop.com.cn:9000/resource-management/2025/01/08/7b96ac9d957c45a7a94b355ca7a89d02.mp4"></video><a-button type="primary" @click="saveCoverImg" :loading="loading">{{ loading ? '截取中': '保存为封面' }}</a-button></div><img :src="coverImg" alt=""></div>
</template>
<script setup>
import { ref, onMounted } from 'vue';const videoRef = ref(null)
const coverImg = ref(null)
const loading = ref(false)function saveCoverImg() {videoRef.value.pause();loading.value = true;const currentTime = videoRef.value.currentTime;createVideo(currentTime)
}function createVideo(currentTime) {const videoElement = document.createElement("video");videoElement.setAttribute("crossorigin", "anonymous"); // 解决跨域问题videoElement.currentTime = currentTimevideoElement.muted = true;videoElement.autoplay = true;videoElement.oncanplay = function () {drawCoverImage(videoElement)}videoElement.src = "https://qt-minio.ictshop.com.cn:9000/resource-management/2025/01/08/7b96ac9d957c45a7a94b355ca7a89d02.mp4";
}function drawCoverImage(vEle) {const c = document.createElement("canvas");const ctx = c.getContext("2d");c.width = vEle.videoWidth;c.height = vEle.videoHeight;ctx.drawImage(vEle, 0, 0, c.width, c.height);const img = c.toDataURL("image/png");coverImg.value = img;loading.value = false;
}</script><style lang="less" scoped>
.box {.video-box {display: flex;align-items: flex-end;video {width: 490px;margin: 10px 10px 0 0;}}img {width: 300px;margin-top: 10px;}
}
</style>
http://www.lryc.cn/news/525454.html

相关文章:

  • [云讷科技]Kerloud Falcon四旋翼飞车虚拟仿真空间发布
  • Jetson nano 安装 PCL 指南
  • go-zero框架基本配置和错误码封装
  • Android中Service在新进程中的启动流程2
  • 论文速读|Matrix-SSL:Matrix Information Theory for Self-Supervised Learning.ICML24
  • ubunut22.04安装docker(基于阿里云 Docker 镜像源安装 Docker)
  • k8s namespace绑定节点
  • 【ElementPlus】在Vue3中实现表格组件封装
  • cursor重构谷粒商城04——vagrant技术快速部署虚拟机
  • 26、正则表达式
  • SpringBoot使用MockMVC通过http请求controller控制器调用测试
  • 【Unity3D】Unity混淆工具Obfuscator使用
  • C语言语法基础学习—动态分配空间(new和malloc的用法及区别)
  • QT:控件属性及常用控件(3)-----输入类控件(正则表达式)
  • Hive SQL 执行计划解析
  • 热更新杂乱记
  • 博客搭建 — GitHub Pages 部署
  • 翻译:How do I reset my FPGA?
  • Linux 进程环境变量:深入理解与实践指南
  • Linux探秘坊-------5.git
  • Linux中的几个基本指令(二)
  • Java入门笔记(1)
  • 设计模式的艺术-开闭原则
  • 【C语言系列】深入理解指针(3)
  • three.js+WebGL踩坑经验合集:写在前面的话
  • 利用Linux的工作队列(Workqueue)实现中断下半部的处理
  • LabVIEW处理复杂系统和数据处理
  • spring-springboot -springcloud
  • DRG/DIP 2.0时代下基于PostgreSQL的成本管理实践与探索(下)
  • 打造本地音乐库