关于在Vue项目中 使用rtsp视频监控的方法(采用h5c).亲测可用!!!

废话不多说,一共六步........

第一步:.https://linkingvision.cn/download/h5stream/  下载最新版本的h5s

第二步:解压后 修改压缩包中的文件 ../conf/h5ss.conf

如下图:

 

第三步:运行根目录下的regservice.bat文件,这个文件只要运行一次就行,以后不需要运行.

第四步:运行h5ss.bat文件,运行后不要关闭,浏览器输入网址http://localhost:8080/demo.html可以查看效果

第五步:在VUE项目中的使用 需要引入两个js文件 h5splayer.js,h5splayerhelper.js 并且这两个js文件必须向外暴露。完整的JS文件 请参考https://github.com/linkingvision/h5svue/tree/master/src/assets

第六步:下面是在VUE中的代码

<template>
  <div class="h5videowrapper h5container" >
    <video class="h5video" id='h5sVideoid' ></video>
  </div>
</template>

<script>
    import {H5sPlayerWS,H5sPlayerHls,H5sPlayerRTC} from '../../store/camera/h5splayer.js'
    import {H5siOS,H5sPlayerCreate} from '../../store/camera/h5splayerhelper.js'
    export default {
        name: 'liveplayer',
        props:['h5id', 'h5videoid'],
        data () {
            return {
                videoid: this.h5videoid,
                h5handler: undefined,
                currtoken: undefined,
                ptzshow: false,
                proto: 'WS'
            }
        },
        activated() {
            console.log(this.h5id, "activated");
        },
        deactivated() {
            console.log(this.h5id, "deactivated");
        },
        beforeDestroy() {
            console.log(this.h5id, "beforeDestroy");
            if (this.h5handler != undefined)
            {
                this.h5handler.disconnect();
                delete this.h5handler;
                this.h5handler = undefined;
            }
            this.currtoken = undefined;
        },
        destroyed() {
            console.log(this.h5id, "destroyed");
        },
        mounted() {
            this.PlayVideo('token1');
        },
        methods: {
            PlayVideo(token)
            {
                if (this.h5handler != undefined)
                {
                    this.h5handler.disconnect();
                    delete this.h5handler;
                    this.h5handler = undefined;
                }
                this.currtoken = token;
                console.log("play ", token);
                var root = process.env.API_ROOT;
                var wsroot = process.env.WS_HOST_ROOT;
                if (root == undefined){
                    root = window.location.protocol + '//' + window.location.host + window.location.pathname;
                }
                if (wsroot == undefined)
                {
                    wsroot = window.location.host;
                }
                var conf1 = {
                    videoid:'h5sVideoid',
                    protocol: window.location.protocol, //'http:' or 'https:'
                    // host: window.location.host, //'localhost:8080'
                    host: 'localhost:8089', //'localhost:8080'
                    rootpath:'/', // '/' or window.location.pathname
                    token:token,
                    hlsver:'v1', //v1 is for ts, v2 is for fmp4
                    session:'c1782caf-b670-42d8-ba90-2244d0b0ee83' //session got from login
                };

                this.h5handler =H5sPlayerCreate(conf1);
                //this.h5handler = new H5sPlayerRTC(conf);

                this.h5handler.connect();
            },
            CloseVideo(event)
            {
                var $container = $("#"+this.h5id);
                var $controls = $container.children(".h5controls");
                var $rtcbutton = $controls.children(".rtcbutton");
                if (this.h5handler != undefined)
                {
                    $rtcbutton.css("display", "none");
                    this.h5handler.disconnect();
                    delete this.h5handler;
                    this.h5handler = undefined;
                    this.$Notice.info({
                        title: "Stop successfully"
                    })
                }

            }
        }
    }
    //fill scale-down
</script>

<style scoped>

  .h5video{
    width: 80%;
    height: 50%;
    background: black;
  }
</style>

注意根据自己的情况 修改h5splayer.js,h5splayerhelper.js 的文件路径,代码中的host端口目前是写死的  这个端口需要和第2步骤h5ss.conf文件中的nHTTPPort保持一致

  • 3
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
Vue 项目播放 RTSP 视频流需要用到插件或者库,常用的有 `vue-video-player` 和 `videojs-contrib-hls`。 下面是一个基于 `vue-video-player` 的示例代码: 1. 安装依赖 ``` npm install --save vue-video-player npm install --save video.js npm install --save hls.js npm install --save flv.js ``` 2. 在 `main.js` 引入依赖 ```javascript import Vue from 'vue'; import VideoPlayer from 'vue-video-player'; import 'video.js/dist/video-js.css'; import 'vue-video-player/src/custom-theme.css'; Vue.use(VideoPlayer); ``` 3. 在组件使用 `<video-player>` 标签 ```html <template> <div> <video-player ref="player" :options="playerOptions"></video-player> </div> </template> ``` 4. 在 `data` 定义 `playerOptions` 对象 ```javascript data() { return { playerOptions: { autoplay: true, muted: true, sources: [{ type: 'video/mp4', src: 'rtsp://your-rtsp-url-here' }], html5: { hls: { enableLowInitialPlaylist: true, smoothQualityChange: true, overrideNative: true }, nativeVideoTracks: false, nativeAudioTracks: false, nativeTextTracks: false }, flash: { hls: { enableLowInitialPlaylist: true, smoothQualityChange: true } } } } } ``` 5. 运行项目,即可在页面播放 RTSP 视频流。 需要注意的是,`vue-video-player` 本身并不支持 RTSP 视频流,需要配合 `hls.js` 或 `flv.js` 进行转换,上述代码使用的是 `hls.js`。 另外,由于 RTSP 视频流的协议限制,需要在服务器端进行 CORS 设置,否则会出现跨域问题。
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值