我获取rtsp流,在vue前端页面显示
app.js页面
const RTSP2web = require('rtsp2web')
// 服务端长连接占据的端口号;你也可以不传,默认是:9999
let port = 9999
const urls =[0,1,2,3]
urls.forEach((url) => {
// 创建一个RTSP2web服务实例出来
new RTSP2web({
port
})
port++
console.log(port,'port');
});
vue页面
<template>
<div class="view">
<p>录像画面</p>
<!-- <div id="video-container">
</div> -->
<div id="canvas">
<!-- <canvas id="canvas-2" style="width: 184px; height: 230px"></canvas>
<canvas id="canvas-3" style="width: 184px; height: 230px"></canvas> -->
<!-- <canvas v-for="(rtsp, index) in rtspList" :key="index" :id="'canvas-' + index"
style="width: 184px; height: 230px"></canvas> -->
</div>
</div>
</template>
<script>
import '../../public/jsmpeg.min.js'
export default {
data() {
return {
players: [],
rtspList: []
};
},
methods: {
},
mounted() {
this.$bus.$on('rtspList', (info) => {
var currentRTSPIndex = 0;
this.rtspList = info
})
var rtsp = 'rtsp://admin:jsrh123456@192.168.2.100:554/Streaming/Channels/101'
window.onload = () => {
// 将rtsp视频流地址进行btoa处理一下
new JSMpeg.Player('ws://localhost:9999/rtsp?url=' + btoa(rtsp), {
canvas: document.getElementById('canvas-2')
})
}
this.rtsps = [
'rtsp://admin:jsrh123456@192.168.2.100:554/Streaming/Channels/201',
'rtsp://admin:jsrh123456@192.168.2.100:554/Streaming/Channels/101',
'rtsp://admin:jsrh123456@192.168.2.100:554/Streaming/Channels/301'
];
for (let i = 0; i < this.rtsps.length; i++) {
const container = document.getElementById('canvas');
const canvas = document.createElement('canvas');
canvas.id = `canvas-${i + 1}`;
canvas.style.width = '184px'; // 设置宽度为200px
canvas.style.height = '230px'; // 设置高度为200px
canvas.style.margin = '3px'; // 设置高度为200px
container.appendChild(canvas);
// var rtsp1 = 'rtsp://admin:jsrh123456@192.168.2.100:554/Streaming/Channels/201'
let url = `ws://localhost:${9999 + i}/rtsp?url=${btoa(this.rtsps[i])}`;
window.onload = () => {
// 将rtsp视频流地址进行btoa处理一下
new JSMpeg.Player(url, { canvas })
}
}
},
watch: {},
computed: {
},
filters: {},
}
</script>
<style scoped>
.view {
width: 380px;
box-sizing: border-box;
}
#video-container {
height: 450px;
}
#video-container canvas {
width: 220px !important;
height: 220px !important;
}
</style>
但是我在页面上每次rtsp都只显示最后一个,这是为什么,代码显示修改了麻烦了