vue-video-player播放hls视频流

news2024/9/22 1:44:35

  需求

最近需要接入海康视频摄像头,然后把视频的画面接入到自己的网站系统中。以前对接过rtsp固定IP的显示视频,这次的不一样,没有了固定IP。海康的解决办法是,摄像头通过配置服务器到萤石云平台,然后购买企业版账号和套餐【注意必须要购买套餐】最便宜的一个月是300元。如果不购买,视频会一直转圈圈,无法播放。

# 萤石云平台官网
https://open.ys7.com

1、购买萤石云平台企业版套餐。

2、购买4G卡的流量,默认500MB,新人注册免费领取2G。官方测评一天流量消耗是8个G。

3、购买4G版的摄像头。

效果图

技术方案

1、摄像头通过4G的SIM卡把视频画面传输到萤石云平台。

2、萤石云平台把视频画面生成https开始m3u8结束的访问地址。

3、VUE通过vue-video-player播放m3u8视频画面。

操作教程

如果前期工作都准备好了可以直接看6789

如果前期工作都准备好了可以直接看6789

如果前期工作都准备好了可以直接看6789

1、配置摄像头

海康4G版的摄像头必须通过网线连接,然后需要一台电脑安装软件【设备网络搜索】,这个摄像头的网线必须和电脑在同一个网段内。

# SADP(设备网络搜索)下载地址
https://www.hikvision.com/cn/support/tools/hitools/clea8b3e4ea7da90a9/  

2、摄像头初始化

安装完成后打开软件,软件会自动搜索到摄像头设备,注意未激活字样是当前的设备,注意看IP,在说明书的最后一页有摄像头默认的IP,如果一样就是当前的这台设备。左边单机设备,然后右边选中【使用萤石云】,输入账号密码和验证码即可。保存后就初始化完成。官网教程地址

# 海康设备接入指南
https://open.ys7.com/bbs/article/34

3、摄像头绑定

切记不要用海康的APP绑定,如果绑定了必须先取消绑定,否则萤石云平台是无法绑定设备的。

4、萤石云平台添加设备

打开萤石云平台, 点击【云接入】-【视频监控控制台】。点击添加新设备,追个添加,输入摄像头的序列号和验证码。添加好了,手动刷新页面,数据不会自动刷新的。

5、企业版购买

6、获取播放地址

【云接入】-【视频监控控制台】-【直播】,然后就能看到生成的访问地址,然后复制地址到VUE代码中。注意播放地址的有效期,后续可以通过代码动态获取播放地址。

# 根据appKey和secret获取accessToken
https://open.ys7.com/help/81

# 获取播放地址
https://open.ys7.com/help/1414


#萤石配网SDK使用说明
https://open.ys7.com/help/38

7、VUE安装插件

# 安装插件 vue2不知道video-player6的版本,只能安装5
npm install vue-video-player@5 --save 

# 安装hls
npm install videojs-contrib-hls --save


8、修改main.js

require('video.js/dist/video-js.css');
require('vue-video-player/src/custom-theme.css');
import hls from 'videojs-contrib-hls';
import VideoPlayer from 'vue-video-player';
 
Vue.use(hls);
Vue.use(VideoPlayer);

9、VUE代码

<template>
	<!-- 详情 -->
	<el-drawer direction="ttb" custom-class="demo-drawer my_drawer1" ref="drawer" title="视频播放测试"
		:visible.sync="openInfo" :before-close="handleClose" :wrapperClosable="false" size="100%"
		style="width: 1000px; margin: 0 auto;" append-to-body>
		<div class="demo-drawer__content">
			<div class="formOutDiv">
				<div style="width: 100%; height: 450px; ">
					<video-player ref="videoPlayer" class="vjs-custom-skin" :options="playerOptions"></video-player>
				</div>
			</div>
		</div>
	</el-drawer>
</template>

<script>
	import {
		getDevice
	} from "@/api/flowinn/device";

	export default {
		name: "Device",
		components: {},
		data() {
			return {
				openInfo: false,
				// 按照如下的配置+底部的css样式就能完成视频铺满DIV的效果,否则两边有黑边
				playerOptions: {
					//  playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度
					autoplay: false, //如果true,浏览器准备好时开始回放。
					muted: false, // 默认情况下将会消除任何音频。
					loop: false, // 导致视频一结束就重新开始。
					preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频(如果浏览器支持)
					language: 'zh-CN',
					// aspectRatio: '16:9', // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
					// fluid: true, // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
					sources: [{
						type: 'application/x-mpegURL',
						src: null, //你的m3u8地址(必填)
					}, ],
					//poster: '', //你的封面地址poster.jpg
					defaultQuality: 0,
					width: '1000px',
					height: '450px',
					hls: true,
					notSupportedMessage: '此视频暂无法播放,请稍后再试', //允许覆盖Video.js无法播放媒体源时显示的默认信息。
				},

			};
		},
		created() {

		},
		methods: {

			// 设备详情页面关闭前事件
			handleClose(done) {
				done();
				let myPlayer = this.$refs.videoPlayer.player;
				myPlayer.pause();
			},
			/** 设备详情,我的方法是在父类页面触发的,自己按照自己的业务配置触发即可 */
			handleInfo(row) {
				let _this = this;
				let myPlayer = this.$refs.videoPlayer.player;
				getDevice(id).then(response => {
					if (response.data.videoUrl != null && response.data.videoUrl != "") {
						// 必须这种赋值,如果是直接用等号赋值播放一会就会报错,
						// The media could not be loaded, either because the server or network failed or because the format is not supported.
						_this.$set(_this.playerOptions.sources, 0, {
							type: "application/x-mpegURL",
							src: response.data.videoUrl,
						});
						// 停止播放
						// myPlayer.pause();
						setTimeout(function() {
							//播放
							myPlayer.play();
						}, 30);
					}

				});
			},

		},

		mounted() {

		}
	};
</script>

<style rel="stylesheet/scss">

</style>
// 以下两个样式就可以完成视频,全屏铺满DIV,不然两边会有黑边
<style rel="stylesheet/scss" lang="scss" scoped>
	::v-deep .video-js .vjs-tech {
		object-fit: fill;
	}

	::v-deep .vjs-poster {
		background-size: cover;
	}
</style>

结束

-----华丽的分割线,以下是凑字数,大家不用花时间看,快去改代码-----

-----华丽的分割线,以下是凑字数,大家不用花时间看,快去改代码-----

-----华丽的分割线,以下是凑字数,大家不用花时间看,快去改代码-----

package cn.renkai721.bean.vo;
 
import lombok.extern.slf4j.Slf4j;
 
@Slf4j
public class MakeUpTheWordCount {
 
    private String make_up_the_word_count_column_999999999_1;
    private String make_up_the_word_count_column_999999999_2;
    private String make_up_the_word_count_column_999999999_3;
    private String make_up_the_word_count_column_999999999_4;
    private String make_up_the_word_count_column_999999999_5;
    private String make_up_the_word_count_column_999999999_6;
    private String make_up_the_word_count_column_999999999_7;
    private String make_up_the_word_count_column_999999999_8;
    private String make_up_the_word_count_column_999999999_9;
    private String make_up_the_word_count_column_999999999_10;
    private String make_up_the_word_count_column_999999999_11;
    private String make_up_the_word_count_column_999999999_12;
    private String make_up_the_word_count_column_999999999_13;
    private String make_up_the_word_count_column_999999999_14;
    private String make_up_the_word_count_column_999999999_15;
    private String make_up_the_word_count_column_999999999_16;
    private String make_up_the_word_count_column_999999999_17;
    private String make_up_the_word_count_column_999999999_18;
    private String make_up_the_word_count_column_999999999_19;
    private String make_up_the_word_count_column_999999999_20;
 
    public String getMake_up_the_word_count_column_999999999_1() {
        return make_up_the_word_count_column_999999999_1;
    }
 
    public void setMake_up_the_word_count_column_999999999_1(String make_up_the_word_count_column_999999999_1) {
        this.make_up_the_word_count_column_999999999_1 = make_up_the_word_count_column_999999999_1;
    }
 
    public String getMake_up_the_word_count_column_999999999_2() {
        return make_up_the_word_count_column_999999999_2;
    }
 
    public void setMake_up_the_word_count_column_999999999_2(String make_up_the_word_count_column_999999999_2) {
        this.make_up_the_word_count_column_999999999_2 = make_up_the_word_count_column_999999999_2;
    }
 
    public String getMake_up_the_word_count_column_999999999_3() {
        return make_up_the_word_count_column_999999999_3;
    }
 
    public void setMake_up_the_word_count_column_999999999_3(String make_up_the_word_count_column_999999999_3) {
        this.make_up_the_word_count_column_999999999_3 = make_up_the_word_count_column_999999999_3;
    }
 
    public String getMake_up_the_word_count_column_999999999_4() {
        return make_up_the_word_count_column_999999999_4;
    }
 
    public void setMake_up_the_word_count_column_999999999_4(String make_up_the_word_count_column_999999999_4) {
        this.make_up_the_word_count_column_999999999_4 = make_up_the_word_count_column_999999999_4;
    }
 
    public String getMake_up_the_word_count_column_999999999_5() {
        return make_up_the_word_count_column_999999999_5;
    }
 
    public void setMake_up_the_word_count_column_999999999_5(String make_up_the_word_count_column_999999999_5) {
        this.make_up_the_word_count_column_999999999_5 = make_up_the_word_count_column_999999999_5;
    }
 
    public String getMake_up_the_word_count_column_999999999_6() {
        return make_up_the_word_count_column_999999999_6;
    }
 
    public void setMake_up_the_word_count_column_999999999_6(String make_up_the_word_count_column_999999999_6) {
        this.make_up_the_word_count_column_999999999_6 = make_up_the_word_count_column_999999999_6;
    }
 
    public String getMake_up_the_word_count_column_999999999_7() {
        return make_up_the_word_count_column_999999999_7;
    }
 
    public void setMake_up_the_word_count_column_999999999_7(String make_up_the_word_count_column_999999999_7) {
        this.make_up_the_word_count_column_999999999_7 = make_up_the_word_count_column_999999999_7;
    }
 
    public String getMake_up_the_word_count_column_999999999_8() {
        return make_up_the_word_count_column_999999999_8;
    }
 
    public void setMake_up_the_word_count_column_999999999_8(String make_up_the_word_count_column_999999999_8) {
        this.make_up_the_word_count_column_999999999_8 = make_up_the_word_count_column_999999999_8;
    }
 
    public String getMake_up_the_word_count_column_999999999_9() {
        return make_up_the_word_count_column_999999999_9;
    }
 
    public void setMake_up_the_word_count_column_999999999_9(String make_up_the_word_count_column_999999999_9) {
        this.make_up_the_word_count_column_999999999_9 = make_up_the_word_count_column_999999999_9;
    }
 
    public String getMake_up_the_word_count_column_999999999_10() {
        return make_up_the_word_count_column_999999999_10;
    }
 
    public void setMake_up_the_word_count_column_999999999_10(String make_up_the_word_count_column_999999999_10) {
        this.make_up_the_word_count_column_999999999_10 = make_up_the_word_count_column_999999999_10;
    }
 
    public String getMake_up_the_word_count_column_999999999_11() {
        return make_up_the_word_count_column_999999999_11;
    }
 
    public void setMake_up_the_word_count_column_999999999_11(String make_up_the_word_count_column_999999999_11) {
        this.make_up_the_word_count_column_999999999_11 = make_up_the_word_count_column_999999999_11;
    }
 
    public String getMake_up_the_word_count_column_999999999_12() {
        return make_up_the_word_count_column_999999999_12;
    }
 
    public void setMake_up_the_word_count_column_999999999_12(String make_up_the_word_count_column_999999999_12) {
        this.make_up_the_word_count_column_999999999_12 = make_up_the_word_count_column_999999999_12;
    }
 
    public String getMake_up_the_word_count_column_999999999_13() {
        return make_up_the_word_count_column_999999999_13;
    }
 
    public void setMake_up_the_word_count_column_999999999_13(String make_up_the_word_count_column_999999999_13) {
        this.make_up_the_word_count_column_999999999_13 = make_up_the_word_count_column_999999999_13;
    }
 
    public String getMake_up_the_word_count_column_999999999_14() {
        return make_up_the_word_count_column_999999999_14;
    }
 
    public void setMake_up_the_word_count_column_999999999_14(String make_up_the_word_count_column_999999999_14) {
        this.make_up_the_word_count_column_999999999_14 = make_up_the_word_count_column_999999999_14;
    }
 
    public String getMake_up_the_word_count_column_999999999_15() {
        return make_up_the_word_count_column_999999999_15;
    }
 
    public void setMake_up_the_word_count_column_999999999_15(String make_up_the_word_count_column_999999999_15) {
        this.make_up_the_word_count_column_999999999_15 = make_up_the_word_count_column_999999999_15;
    }
 
    public String getMake_up_the_word_count_column_999999999_16() {
        return make_up_the_word_count_column_999999999_16;
    }
 
    public void setMake_up_the_word_count_column_999999999_16(String make_up_the_word_count_column_999999999_16) {
        this.make_up_the_word_count_column_999999999_16 = make_up_the_word_count_column_999999999_16;
    }
 
    public String getMake_up_the_word_count_column_999999999_17() {
        return make_up_the_word_count_column_999999999_17;
    }
 
    public void setMake_up_the_word_count_column_999999999_17(String make_up_the_word_count_column_999999999_17) {
        this.make_up_the_word_count_column_999999999_17 = make_up_the_word_count_column_999999999_17;
    }
 
    public String getMake_up_the_word_count_column_999999999_18() {
        return make_up_the_word_count_column_999999999_18;
    }
 
    public void setMake_up_the_word_count_column_999999999_18(String make_up_the_word_count_column_999999999_18) {
        this.make_up_the_word_count_column_999999999_18 = make_up_the_word_count_column_999999999_18;
    }
 
    public String getMake_up_the_word_count_column_999999999_19() {
        return make_up_the_word_count_column_999999999_19;
    }
 
    public void setMake_up_the_word_count_column_999999999_19(String make_up_the_word_count_column_999999999_19) {
        this.make_up_the_word_count_column_999999999_19 = make_up_the_word_count_column_999999999_19;
    }
 
    public String getMake_up_the_word_count_column_999999999_20() {
        return make_up_the_word_count_column_999999999_20;
    }
 
    public void setMake_up_the_word_count_column_999999999_20(String make_up_the_word_count_column_999999999_20) {
        this.make_up_the_word_count_column_999999999_20 = make_up_the_word_count_column_999999999_20;
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1361185.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【unity小技巧】实现没有动画的FPS武器摇摆和摆动效果

文章目录 前言开始完结 前言 添加程序摇摆和摆动是为任何FPS游戏添加一些细节的非常简单的方法。但是并不是所以的模型动画都会配有武器摆动动画效果&#xff0c;在本文中&#xff0c;将实现如何使用一些简单的代码实现武器摇摆和摆动效果&#xff0c;这比设置动画来尝试实现类…

调整几行代码,接口吞吐提升 10 倍,性能调优妙啊!

景 分析过程 总结 背景 公司的一个ToB系统,因为客户使用的也不多,没啥并发要求,就一直没有经过压测。这两天来了一个“大客户”,对并发量提出了要求:核心接口与几个重点使用场景单节点吞吐量要满足最低500/s的要求。 当时一想,500/s吞吐量还不简单。Tomcat按照100个线程…

小心JDK20 ZipOutputStream

Oracle 團隊竟然這麽粗心&#xff0c;編譯JDK 20 時ZipOutputStream沒有編譯成功就發佈了。 所以這個20版本不可以使用ZipOutputStream。 GZIPInputStream 只能做最後的壓縮&#xff0c;不能添加多個附件ZipEntry。 下一個版本21不存在這個問題。 try(var zipOut new ZipOu…

C++之STL库简介

目录 一、STL&#xff08;Standard Template Library&#xff0c;标准模板库&#xff09; 二、容器&#xff08;Containers&#xff09; 1.vector&#xff08;动态数组&#xff09; 2.list&#xff08;双向链表&#xff09; 3.deque&#xff08;双端队列&#xff09; 4.st…

怎么做表单二维码来获取用户数据?扫码填表的制作方法

​怎么用二维码来收集其他人的信息&#xff0c;比如用户反馈、信息采集、问卷调查等等&#xff0c;都是现在表单二维码的常见应用方式。那么如果我们想制作一个表单二维码用来采集其他人员的反馈信息&#xff0c;用二维码生成器来制作的步骤有哪些呢&#xff1f;下面来教大家在…

Redis高级特性和应用(慢查询、Pipeline、事务、Lua)

Redis的慢查询 许多存储系统(例如 MySQL)提供慢查询日志帮助开发和运维人员定位系统存在的慢操作。所谓慢查询日志就是系统在命令执行前后计算每条命令的执行时间,当超过预设阀值,就将这条命令的相关信息(例如:发生时间,耗时,命令的详细信息)记录下来,Redis也提供了类似…

高压放大器输出接法及其注意事项

高压放大器应用场景非常广泛&#xff0c;非常适用于半导体高压驱动、TFT产业高压驱动、各种高压工程等应用&#xff1b;也很适用当作音频信号产生器或函数波形产生器的波形放大使用。使用场景广泛&#xff0c;放大器的输出接法也多种&#xff0c;对于不同的放大器也有对应的输出…

Linux vi/vim 教程

文章目录 【 1. vi/vim 的三种模式 】1.1 命令模式1.2 输入模式1.3 底线命令模式 【 2. 实例 】【 3. vim 的其他命令 】 所有的 Unix Like 系统都会内建 vi 文本编辑器&#xff0c;其他的文本编辑器则不一定会存在。目前我们使用比较多的是 vim 编辑器。vim 从 vi 发展出来&am…

Leetcode 剑指 Offer II 060. 前 K 个高频元素

题目难度: 中等 原题链接 今天继续更新 Leetcode 的剑指 Offer&#xff08;专项突击版&#xff09;系列, 大家在公众号 算法精选 里回复 剑指offer2 就能看到该系列当前连载的所有文章了, 记得关注哦~ 题目描述 给定一个整数数组 nums 和一个整数 k &#xff0c;请返回其中出现…

【Java集合篇】接上篇博文--为什么在JDK8中HashMap要转成红黑树

为什么在JDK8中HashMap要转成红黑树 ✔️为什么不继续使用链表✔️为什么是红黑树✔️红黑树的性能优势 ✔️ 拓展知识仓✔️为什么是链表长度达到8的时候转✔️为什么不在冲突的时候立刻转✔️关于为什么长度为8的时候转(源码注释解读)✔️为什么长度为6的时候转回来?✔️双向…

使用jmeter从0开始完成性能测试

使用JMeter从0开始完成性能测试 介绍 在软件开发过程中&#xff0c;性能测试是一项关键任务&#xff0c;它可以帮助我们评估系统在不同负载条件下的性能表现&#xff0c;发现潜在的性能瓶颈。JMeter是一款功能强大且易于使用的性能测试工具&#xff0c;它可以帮助我们完成各种…

iec104和iec61850

iec104和iec61850 IEC104 规约详细解读(一) 协议结构 IEC104 规约详细解读(二)交互流程以及协议解析 61850开发知识总结与分享【1】 Get the necesarry projects next to each other in the same directory; $ git clone https://github.com/robidev/iec61850_open_server.g…

NGUI基础-Widget

目录 Widget是什么 Widget组件包含的属性 Pivot Depth Size snap Aspect Free Based on Width Based on Height Widget是什么 在Unity UI系统中&#xff0c;"Widget"是指UI元素的基类&#xff0c;它为UI元素提供了位置、大小和锚点等基本属性。通过使用&qu…

VINS-MONO拓展2----更快地makeHessian矩阵

1. 目标 完成大作业T2 作业提示&#xff1a; 多线程方法主要包括以下几种(参考博客)&#xff1a; MPI(多主机多线程开发),OpenMP(为单主机多线程开发而设计)SSE(主要增强CPU浮点运算的能力)CUDAStream processing, 之前已经了解过std::thread和pthread&#xff0c;拓展1…

冠军团队!第二届百度搜索创新大赛AI方案

Datawhale干货 作者&#xff1a;李柯辰&#xff0c;Datawhale成员 写在前面 大家好&#xff0c;我们是2023年第二届百度搜索创新大赛 赛道三——AI应用设计赛道的冠军团队——“肝到凌晨”&#xff0c;很高兴能与大家分享我们这次比赛的经验&#xff0c;同时也希望以后有机会可…

【机器学习:欧氏距离 】机器学习中欧氏距离的理解和应用

【机器学习&#xff1a;欧氏距离 】机器学习中欧氏距离的理解和应用 距离公式二维更高的维度点以外的物体属性欧几里得距离的平方概括历史 在数学中&#xff0c;欧氏距离’是指欧氏空间中任意两点之间的直线距离。这种距离可以通过应用勾股定理来计算&#xff0c;利用两点的笛卡…

【userfaultfd 条件竞争】starCTF2019 - hackme

前言 呜呜呜&#xff0c;这题不难&#xff0c;但是差不多一个多月没碰我的女朋友 kernel pwn 了&#xff0c;对我的 root 宝宝也是非常想念&#xff0c;可惜这题没有找到我的 root 宝宝&#xff0c;就偷了她的 flag。 哎有点生疏了&#xff0c;这题没看出来堆溢出&#xff0c…

【漏洞复现】ActiveMQ反序列化漏洞(CVE-2015-5254)

Nx01 产品简介 Apache ActiveMQ是Apache软件基金会所研发的开放源代码消息中间件。ActiveMQ是消息队列服务&#xff0c;是面向消息中间件&#xff08;MOM&#xff09;的最终实现&#xff0c;它为企业消息传递提供高可用、出色性能、可扩展、稳定和安全保障。 Nx02 漏洞描述 Re…

漫谈大模型的[幻觉]问题

# 如何解决大模型的幻觉问题&#xff1f;# &#x1f3ac;个人简介&#xff1a;一个全栈工程师的升级之路&#xff01; &#x1f4cb;个人专栏&#xff1a;漫谈LLMs带来的AIGC浪潮​​​​​​​ &#x1f380;CSDN主页 发狂的小花 &#x1f304;人生秘诀&#xff1a;学习的本质…

C#中的值和引用笔记

文章目录 1. 简单介绍2. 如何判断值类型和引用类型3. 语句块4. 变量的生命周期5. 结构体中的值和引用6. 数组中的存储规则7. 结构体继承接口 1. 简单介绍 2. 如何判断值类型和引用类型 在代码中直接转到内部F12 如string类型 值类型int 3. 语句块 4. 变量的生命周期 5. 结构…