采用新的rtsp拉流

dongguan-华为云
LAPTOP-S9HJSOEB\昊天 1 year ago
parent f3b77612c3
commit b147e14230

@ -1,22 +1,46 @@
<template> <template>
<a-row type="flex-container" :gutter="30"> <div>
<a-col > <a-row>
时间<a-date-picker <a-col span="9">
v-model="date" 时间<a-range-picker
format="YYYY-MM-DD" :show-time="{ format: 'HH:mm:ss' }"
placeholder="请选择时间" v-model="date"
@change="cameraRecord" format="YYYY-MM-DD HH:mm:ss"
/> @change="cameraRecord"
</a-col> />
<label for="name">摄像机:</label> </a-col>
<select v-model="selectedCamera" > <a-col span="6">
<option v-for="(url, camera) in cameras" :key="url.camera" >{{ camera }}</option> <label for="name">球机: </label>
</select> <a-select
<div id="hikvideo"> @change="handleChange"
<video id='video' controls autoplay muted width="50%" height="50%" style="object-fit: fill"></video> v-model="selectedCamera"
</div> style="width:200px"
</a-row> :allowClear="true"
</template> >
<a-select-option
v-for="(url, camera) in cameras"
:key="url"
>{{ camera }}</a-select-option>
</a-select>
</a-col>
</a-row>
<a-row>
<div id="hikvideo">
<video
id='video'
controls
autoplay
muted
width="50%"
height="50%"
style="object-fit: fill"
></video>
</div>
</a-row>
</div>
</template>
<script> <script>
export default { export default {
name: "hikvideo", name: "hikvideo",
@ -28,35 +52,85 @@ export default {
return time.getTime() > Date.now(); return time.getTime() > Date.now();
}, },
}, },
date: '', date: [],
cameras: null, cameras: null,
selectedCamera: null url: null,
selectedCamera: null,
}; };
}, },
mounted() { mounted() {
this.loadCameras(); this.loadCameras();
this.webRtcServer = new WebRtcStreamer("video", "http://127.0.0.1:8000"); this.webRtcServer = new WebRtcStreamer(
//this.webRtcServer.connect("rtsp://132.239.12.145/axis-media/media.amp"); "video",
"http://192.168.1.200:8000"
);
}, },
// //
beforeDestroy() { beforeDestroy() {
this.webRtcServer.disconnect() this.webRtcServer.disconnect();
this.webRtcServer = null this.webRtcServer = null;
}, },
methods: { methods: {
convertDateFormat(input) {
// 使
const regex = /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/;
const match = input.match(regex);
if (match) {
const year = match[1];
const month = match[2];
const day = match[3];
const hours = match[4];
const minutes = match[5];
const seconds = match[6];
// YYYYMMDDtHHmmssz
return `${year}${month}${day}t${hours}${minutes}${seconds}z`;
} else {
throw new Error("Invalid date format");
}
},
handleChange(value) {
console.log(value);
this.url = value;
this.play()
},
play() {
if (this.date != null && this.url != null) {
var url =
this.url +
"starttime=" +
this.convertDateFormat(this.date[0]) +
"&endtime=" +
this.convertDateFormat(this.date[1]);
console.log(url);
this.webRtcServer.connect(
"rtsp://admin:a1234567@192.168.1.65:554/Streaming/Channels/101"
);
}
},
onSubmit() {
console.log(this.selectedCamera);
},
cameraRecord(date, dateString) {
console.log(dateString);
this.date = dateString;
this.play()
},
loadCameras() { loadCameras() {
fetch('./config.json') fetch("./config.json")
.then(response => response.json()) .then((response) => response.json())
.then(data => { .then((data) => {
this.cameras = data.urls; this.cameras = data.urls;
this.camera = data.urls.video; this.camera = data.urls.video;
console.log("11111111111111111111111111111111111111111111"); console.log("11111111111111111111111111111111111111111111");
console.log(this.cameras); console.log(this.cameras);
}) })
.catch(error => { .catch((error) => {
console.error('Error fetching JSON file:', error); console.error("Error fetching JSON file:", error);
}); });
} },
}, },
}; };
</script> </script>
Loading…
Cancel
Save