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

vue视频流播放,支持多种视频格式,如rmvb、mkv

先将视频转码为ts

ffmpeg -i C:\test\3.rmvb -codec: copy -start_number 0 -hls_time 10 -hls_list_size 0 -f hls C:\test\a\output.m3u8
在这里插入图片描述

后端配置接口


import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.net.MalformedURLException;
import java.nio.file.Path;
import java.nio.file.Paths;@RestController
@RequestMapping("/api/video")
public class VideoController4 {private final Path videoStorageLocation = Paths.get("C:\\test\\a");@GetMapping("/stream/{fileName}")public ResponseEntity<Resource> streamVideo(@PathVariable String fileName) {try {Path filePath = this.videoStorageLocation.resolve(fileName).normalize();System.out.println(filePath);Resource resource = new UrlResource(filePath.toUri());if (resource.exists()) {return ResponseEntity.ok().header(HttpHeaders.CONTENT_TYPE, "application/x-mpegURL").body(resource);} else {return ResponseEntity.notFound().build();}} catch (MalformedURLException ex) {return ResponseEntity.badRequest().build();}}
}

vue代码

<template><div><video ref="videoPlayer" controls ></video></div>
</template>
import Hls from 'hls.js';
onMounted(() => {const video = videoPlayer.value;const videoSrc = 'http://localhost:9500/api/video/stream/5.m3u8'; // 替换为你的 .m3u8 视频流地址if (Hls.isSupported() && video) {const hls = new Hls();hls.loadSource(videoSrc);hls.attachMedia(video);hls.on(Hls.Events.MANIFEST_PARSED, () => {// video.play();});} else if (video && video.canPlayType('application/vnd.apple.mpegurl')) {// 如果浏览器原生支持 HLS(如 Safari)video.src = videoSrc;video.addEventListener('loadedmetadata', () => {video.play();});}
});

在这里插入图片描述

http://www.lryc.cn/news/524990.html

相关文章:

  • 记一个Timestamp时区问题的坑
  • 新年好(Dijkstra+dfs/全排列)
  • 如何“看到” Spring 容器?
  • 怎么使用CRM软件?操作方法和技巧有哪些?
  • Spingboot整合Netty,简单示例
  • grafana新增email告警
  • Github 2025-01-20 开源项目周报 Top15
  • 【Rabbitmq】Rabbitmq高级特性-发送者可靠性
  • K8S中Service详解(一)
  • Effective C++读书笔记——item23(用非成员,非友元函数取代成员函数)
  • 云原生前端开发:打造现代化高性能的用户体验
  • 循环队列(C语言版)
  • 考研408笔记之数据结构(五)——图
  • 没有公网IP实现seafile本地IP访问和虚拟局域网IP同时访问和上传文件
  • 【Hadoop面试题2025】
  • 2000-2010年各省第三产业就业人数数据
  • 第十一讲 多线程
  • VUE之路由Props、replace、编程式路由导航、重定向
  • windows安装ES
  • 论文速读|Multi-Modal Disordered Representation Learning Network for TBPS.AAAI24
  • 小哆啦解题记:加油站的奇幻冒险
  • 【前端】CSS实战之音乐播放器
  • Games104——渲染中光和材质的数学魔法
  • impala增加字段,hsql查不到数据
  • SpringBoot项目中的异常处理
  • ComfyUI实现老照片修复——AI修复老照片(ComfyUI-ReActor / ReSwapper)尚待完善
  • NLTK命名实体识别(NER)
  • 【游戏设计原理】78 - 持续注意力
  • Android设备:Linux远程lldb调试
  • 多层 RNN原理以及实现