45 对接海康视频九宫格的实现

这篇具有很好参考价值的文章主要介绍了45 对接海康视频九宫格的实现。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

前言

这里主要是 来看一下 海康视频 的一个九宫格播放的需求

然后 在实际使用的过程中产生了一些问题, 比如 增加一个视频, 应该只增量请求这一个视频的服务, 而一些实现下是全量请求了 整个视频列表的服务

另外 就是全屏播放, 如果是 自己写样式来实现 全屏播放, 可能需要 重新创建 海康的player, 进而 需要重新请求 海康的视频服务

另外 还有 cpu, 内存占用过高的情况, 然后 还有一些疑似 内存泄露的情况

这里 调整一个版本 记录一下

以下有一些版本, 一个是自定义实现九宫格, 这样做的问题 还是挺多的, 以上的问题基本上都占了, 然后另外一个版本是 直接使用 海康自己提供的 api 来实现 九宫格, 会稍微好一些

 文章来源地址https://www.toymoban.com/news/detail-851660.html

 

整体来说, 一个比较良好的情况是, 否则的话 可能会出现一些 较高的资源占用的问题

  1. 新增一个视频的时候, 仅仅增量请求这一个视频的数据, 增量的和海康建立连接
  2. 全屏的时候 使用海康的 api, 它自己已经实现了 自适应, 否则 自己处理的话 自适应有可能需要重新和海康建立连接, 重新渲染
  3. 尽量避免 并发 和请求海康的接口, 经常会崩溃, 尽量避免 频繁的和海康断开视频连接, 重新创建视频连接

 

 

自己自定义九宫格

这个就相当于是 海康的视频播放器只播放一个视频

然后 这里是 循环 codeUrlList, 一个视频对应于一个 player, 虽然同时 播放了多个 player 但是 实际上核心占用资源的貌似是其中一个

key 需要指定, 否则 在一些需要重新渲染 海康player 的场景下面, 模型改变了 但是每一个 div 内部的 player 的 dom 不会重新渲染, 可能会导致 视频错位等问题

这个 问题就是需要自己实现全屏的样式, 以及全拼的时候需要全部重新渲染一次, 才能适应全屏之后的窗口

其他的 增量的获取海康服务, 避免并发的请求海康接口 就需要自己处理了

以下的测试代码 看 (!singlePlayer) 部分

 

业务组件如下

<template>
  <div class="indexDiv">
    <div v-if="!singlePlayer" v-for="item in codeUrlList" :key="item.code" style="width:400px; display: inline; float:left;">
      <Player :palyer-code="item.code" :play-url="item.url"></Player>
    </div>
  
    <PlayerSplitByHk ref="playerHk" v-if="singlePlayer"></PlayerSplitByHk>
    <button @click="handleFullScreen" >全屏</button>
  </div>
</template>

<script>

import Player from "./Player.vue"
import PlayerSplitByHk from "./PlayerSplitByHk.vue"

export default {
  name: "Index",
  components: {
    Player,
    PlayerSplitByHk,
  },
  data() {
    return {
    singlePlayer: false,
    codeUrlList: [{"code":"61092100561310001001","url":"ws://112.110.110.109/openUrl/KG6aIkE"},{"code":"61102600581328004001","url":"ws://112.110.110.109:559/openUrl/KHubaKc"},{"code":"61092200561310001001","url":"ws://112.110.110.109:559/openUrl/KIs4xbO"},{"code":"61092200561310001002","url":"ws://112.110.110.109:559/openUrl/KJcCKwo"},{"code":"61092200561310002701","url":"ws://112.110.110.109/openUrl/KK6g812"},{"code":"61092200561310001901","url":"ws://112.110.110.109:559/openUrl/KL11U1W"},{"code":"61092800561310002101","url":"ws://112.110.110.109:559/openUrl/KLJjkk0"},{"code":"61092800561310002402","url":"ws://112.110.110.109:559/openUrl/KMu98ME"},{"code":"61092800561310002901","url":"ws://112.110.110.109/openUrl/KNaIYik"}]
    };
  },
  mounted() {
    // test for hk sudoku
    if(this.singlePlayer) {
      this.$refs.playerHk.updateCodeUrlList(this.codeUrlList)
      // call updateCodeUrlList if codeUrlList updated

      let _this = this
      setTimeout(function() {
        let updatedCodeUrlList = []
        _this.codeUrlList.map(ele => updatedCodeUrlList.push(ele))
        updatedCodeUrlList.splice(5, 3)
        _this.$refs.playerHk.updateCodeUrlList(updatedCodeUrlList)
        console.log(" splice with idx 6, 7, 8 ")
        console.log(" ----------------------------- ")
      }, 5000)
      setTimeout(function() {
        let updatedCodeUrlList = []
        _this.codeUrlList.map(ele => updatedCodeUrlList.push(ele))
        updatedCodeUrlList.splice(5, 3)
        updatedCodeUrlList.push({code: "code1", url: "url1"})
        updatedCodeUrlList.push({code: "code2", url: "url2"})
        _this.$refs.playerHk.updateCodeUrlList(updatedCodeUrlList)
        console.log(" push url1, url2 ")
        console.log(" ----------------------------- ")
      }, 10000)
    }
  },
  methods: {
    handleFullScreen() {
      // test for hk sudoku
      if(this.singlePlayer) {
        this.$refs.playerHk.handleFullScreen()
      }
    }
  }
}

</script>

<style scoped>

</style>

 

视频播放组件如下

<template>
  <div clas="outerDiv" >
    <div class="main" :id="'playerDiv' + this.palyerCode"  ></div>
  </div>
</template>

<script>

export default {
  name: "Player",
  props: {
    palyerCode: {
      type: String,
      default: "",
    },
    playUrl: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      player: null
    };
  },
  mounted() {
    this.createPlayer()
    this.startPlay()
  },
  methods: {
    createPlayer() {
      this.player = new window.JSPlugin({
        szId: 'playerDiv' + this.palyerCode,
        szBasePath: "./",
        iMaxSplit: 4,
        iCurrentSplit: 1,
        openDebug: true,
        oStyle: {
          borderSelect: '#000',
        }
      })

      // 事件回调绑定
    let _this = this
      this.player.JS_SetWindowControlCallback({
        windowEventSelect: function (iWndIndex) {  //插件选中窗口回调
          console.log('windowSelect callback: ', iWndIndex);
          _this.player.JS_Stop(iWndIndex).then(
            () => { console.log('stop play ' + iWndIndex + ' success') },
            e => { console.error(e) }
          )
        },
        pluginErrorHandler: function (iWndIndex, iErrorpalyerCode, oError) {  //插件错误回调
          console.log('pluginError callback: ', iWndIndex, iErrorpalyerCode, oError);
        },
        windowFullCcreenChange: function (bFull) {  //全屏切换回调
          console.log('fullScreen callback: ', bFull);
        },
        firstFrameDisplay: function (iWndIndex, iWidth, iHeight) {  //首帧显示回调
          console.log('firstFrame loaded callback: ', iWndIndex, iWidth, iHeight);
        },
        performanceLack: function () {  //性能不足回调
          console.log('performanceLack callback: ');
        }
      });
    },
    startPlay() {
      let playURL = this.playUrl
      let model = 1
      console.log(" start replay with url : " + playURL)
      // this.player.JS_Play(playURL, { playURL, model }, 0).then(
      //     () => { console.log('realplay success') },
      //     e => { console.error(e) }
      // )
    }
  }
}

</script>

<style scoped>

</style>

 

 

使用 hik 提供的 api 实现九宫格

这里的九宫格的实现就是直接基于 hk 的 api 了, 比如这里的 this.player.JS_ArrangeWindow, this.player.JS_Play 

然后 全屏基于 this.player.JS_FullScreenDisplay, 然后 全拼的状态可以通过 windowFullCcreenChange 进行获取

一些 常见的回调函数, 也在 demo 中有体现

然后 降低客户端和海康服务器这边的开销的处理, 主要是如下的 更新前后的视频列表, 如果目标索引的视频变了, 才重新发起请求, 重新建立视频连接

 

这样的话 开始的时候点击九个视频, 资源占用大概是 cpu100%, 内存差不多是 500M 左右, 然后 随着时间的推移, 主项目的js引擎[不是海康player的js引擎] 占用内存逐渐升高, 这个具体就得看这个 player 的问题了, 然后刷新 Index.vue 的页面, 这个内存占用 依然存在

这里 就不深究了

 

业务组件如下

<template>
  <div class="indexDiv">
    <div v-if="!singlePlayer" v-for="item in codeUrlList" :key="item.code" style="width:400px; display: inline; float:left;">
      <Player :palyer-code="item.code" :play-url="item.url"></Player>
    </div>
  
    <PlayerSplitByHk ref="playerHk" v-if="singlePlayer"></PlayerSplitByHk>
    <button @click="handleFullScreen" >全屏</button>
  </div>
</template>

<script>

import Player from "./Player.vue"
import PlayerSplitByHk from "./PlayerSplitByHk.vue"

export default {
  name: "Index",
  components: {
    Player,
    PlayerSplitByHk,
  },
  data() {
    return {
    singlePlayer: false,
    codeUrlList: [{"code":"61092100561310001001","url":"ws://112.110.110.109/openUrl/KG6aIkE"},{"code":"61102600581328004001","url":"ws://112.110.110.109:559/openUrl/KHubaKc"},{"code":"61092200561310001001","url":"ws://112.110.110.109:559/openUrl/KIs4xbO"},{"code":"61092200561310001002","url":"ws://112.110.110.109:559/openUrl/KJcCKwo"},{"code":"61092200561310002701","url":"ws://112.110.110.109/openUrl/KK6g812"},{"code":"61092200561310001901","url":"ws://112.110.110.109:559/openUrl/KL11U1W"},{"code":"61092800561310002101","url":"ws://112.110.110.109:559/openUrl/KLJjkk0"},{"code":"61092800561310002402","url":"ws://112.110.110.109:559/openUrl/KMu98ME"},{"code":"61092800561310002901","url":"ws://112.110.110.109/openUrl/KNaIYik"}]
    };
  },
  mounted() {
    // test for hk sudoku
    if(this.singlePlayer) {
      this.$refs.playerHk.updateCodeUrlList(this.codeUrlList)
      // call updateCodeUrlList if codeUrlList updated

      let _this = this
      setTimeout(function() {
        let updatedCodeUrlList = []
        _this.codeUrlList.map(ele => updatedCodeUrlList.push(ele))
        updatedCodeUrlList.splice(5, 3)
        _this.$refs.playerHk.updateCodeUrlList(updatedCodeUrlList)
        console.log(" splice with idx 6, 7, 8 ")
        console.log(" ----------------------------- ")
      }, 5000)
      setTimeout(function() {
        let updatedCodeUrlList = []
        _this.codeUrlList.map(ele => updatedCodeUrlList.push(ele))
        updatedCodeUrlList.splice(5, 3)
        updatedCodeUrlList.push({code: "code1", url: "url1"})
        updatedCodeUrlList.push({code: "code2", url: "url2"})
        _this.$refs.playerHk.updateCodeUrlList(updatedCodeUrlList)
        console.log(" push url1, url2 ")
        console.log(" ----------------------------- ")
      }, 10000)
    }
  },
  methods: {
    handleFullScreen() {
      // test for hk sudoku
      if(this.singlePlayer) {
        this.$refs.playerHk.handleFullScreen()
      }
    }
  }
}

</script>

<style scoped>

</style>

 

视频播放组件如下

<template>
  <div class="outerDiv" >
    <div class="main" id="playerDiv" ></div>
  </div>
</template>

<script>

export default {
  name: "PlayerSplitByHk",
  props: {
  },
  data() {
    return {
      player: null,
      videoListMax: 0,
      isFirstClick: false,
      codeUrlList: null,
    };
  },
  mounted() {
    this.createPlayer()
  },
  methods: {
    updateCodeUrlList(newCodeUrlList) {
      let oldCodeUrlList = this.codeUrlList
      this.codeUrlList = newCodeUrlList
      this.videoListMax = Math.max(this.videoListMax, newCodeUrlList.length)
      let matrixLen = newCodeUrlList.length > 4 ? 3 : (newCodeUrlList.length > 1 ? 2 : 1)

      this.isFirstClick = true
      this.player.JS_ArrangeWindow(matrixLen)
      for(let i=newCodeUrlList.length; i<this.videoListMax; i++) {
        console.log(" stop replay with idx : " + i)
        this.player.JS_Stop(i);
      }

      for(let i=0; i<newCodeUrlList.length; i++) {
        let newItem = newCodeUrlList[i]
        let oldItem = oldCodeUrlList && oldCodeUrlList[i]
        if((!oldItem) || (oldItem.code !== newItem.code)) {
          this.startPlay(i)
        }
      }
    },
    handleFullScreen() {
      this.player.JS_FullScreenDisplay(true).then(
          () => { console.log(`wholeFullScreen success`) },
          e => { console.error(e) }
      )
    },
    createPlayer() {
      this.player = new window.JSPlugin({
        szId: 'playerDiv',
        szBasePath: "/static",
        iMaxSplit: 9,
        iCurrentSplit: 1,
        iWidth: 400,
        iHeight: 300,
        openDebug: true,
        oStyle: {
          // border: '#green',
          // borderSelect: '#ffcc00',
        }
      })

    // 事件回调绑定
    let _this = this
      this.player.JS_SetWindowControlCallback({
        windowEventSelect: function (iWndIndex) {  //插件选中窗口回调
          if(_this.isFirstClick) {
            _this.isFirstClick = false
            return ;
          }
          console.log(" do what you want ")
        },
        pluginErrorHandler: function (iWndIndex, iErrorpalyerCode, oError) {
          console.log('pluginError callback: ', iWndIndex, iErrorpalyerCode, oError);
        },
        windowFullCcreenChange: function (bFull) {
          console.log('fullScreen callback: ', bFull);
        },
        firstFrameDisplay: function (iWndIndex, iWidth, iHeight) {
          console.log('firstFrame loaded callback: ', iWndIndex, iWidth, iHeight);
        },
        performanceLack: function () {
          console.log('performanceLack callback: ');
        }
      });
    },
    startPlay(idx) {
      let playURL = this.codeUrlList[idx].url
      let model = 1
      console.log(" start replay with idx : " + idx)
      // this.player.JS_Play(playURL, { playURL, model }, idx).then(
      //     () => { console.log('realplay success') },
      //     e => { console.error(e) }
      // )
    }
  }
}

</script>

<style scoped>

</style>

 

 

完 

 

 

 

到了这里,关于45 对接海康视频九宫格的实现的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • vue2 对接 海康摄像头插件 (视频WEB插件 V1.5.2)

    前言 海康视频插件v.1.5.2版本运行环境需要安装插件VideoWebPlugin.exe,对浏览器也有兼容性要求,具体看官方文档 对应下载插件 去海康官网下载插件 里面有dome等其他需要用到的 地址: 安装插件 打开下载的文件里的bin文件 安装一下VideoWebPlugin vue脚手架中集成插件 把官方资源

    2024年02月03日
    浏览(38)
  • 前后端 java 对接海康威视监控-hls实现h5播放

    海康的获取监控预览流的接口当中支持 rtsp、rtmp、hls等协议。 这篇文章主要是说hls协议的。 贴上海康的开发平台地址,其中有对应的API:海康开发平台 这里除了main方法之外,有两个方法,分别是: 1)分页获取监控点资源。 即返回所有的监控点信息。 2)获取监控点预览取

    2024年02月08日
    浏览(37)
  • web前端——HTML+CSS实现九宫格

    web前端——HTML+CSS实现九宫格

    2024年02月05日
    浏览(34)
  • vue对接海康web1.5.2开发包,实现摄像头画面展示

    目录 前言 一、首先下载视频web插件v.1.5.2版本 二、利用官方插件包进行相关需求开发 1.官方插件包和开发文档的下载 2.在项目中引入插件包的相关的js (1)下载完成后打开 (2)在项目中public文件下创建一个文件夹放视频插件js 3..new 一个WebControl 插件相关实例  (1)创建Web

    2024年02月08日
    浏览(36)
  • vue2使用rtsp视频流接入海康威视摄像头(纯前端)

    海康威视官方的RTSP最新取流格式如下: rtsp://用户名:密码@IP:554/Streaming/Channels/101 用户名和密码 IP就是登陆摄像头时候的IP(笔者这里IP是192.168.1.210) 所以笔者的rtsp流地址就是 rtsp://用户名:密码@192.168.1.210:554/Streaming/Channels/101 1.1关闭 萤石云的接入 1.2 调整视频编码为H.264 在此下载

    2024年04月26日
    浏览(41)
  • vue前端对接监控视频 FLV格式 (分屏的操作 单屏 ,四平 ,六屏)

    vue前端对接监控视频 FLV格式 提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档 接触智慧园区,智慧工地,水泵站等项目之后,发现都有实时监控的对接,并且是可以多屏进行,就研究了相关的技术栈,找到了这个强大的播放器对前端还是很友好的,话

    2024年02月03日
    浏览(32)
  • 【vue2】前端如何播放rtsp 视频流,拿到rtsp视频流地址如何处理,海康视频rtsp h264 如何播放

    最近在写vue2 项目其中有个需求是实时播放摄像头的视频,摄像头是 海康 的设备,搞了很长时间终于监控视频出来了,记录一下,放置下次遇到。文章有点长,略显啰嗦请耐心看完。 测试?测试什么?测试rtsp视频流能不能播放。 video mediaplay官网 即(VLC) 下载、安装完VLC后

    2024年02月05日
    浏览(39)
  • 海康 综合安防管理平台 对接

    1.1 官网介绍 1.2 个人理解 综合安防管理平台部署之后,有2个系统,一个是综合安防管理平台:是用户端系统,一个是运营中心:是综合安防平台的后台管理系统,可提供api与业务平台对接,实现实时预览、录播回放、语音对讲、报警订阅等功能。 1.3 综合安防管理平台 1.4 运

    2024年02月06日
    浏览(31)
  • FFMPEG+mediamtx 实现海康相机视频播放

    使用FFMPEG对海康相机视频进行读取,重新编码后再进行推流,推到mediamtx,再通过网页播放器或其他客户端拉取视频并播放 随便找的一个安装教程:https://blog.csdn.net/weixin_44704985/article/details/109532224 安装后需配置到环境变量 https://github.com/bluenviron/mediamtx/releases 要是打不开自己

    2024年02月07日
    浏览(36)
  • 海康摄像头web3.3前端实现

     上篇我发布了一篇文章,有一个刷新页面摄像头就消失的bug,这个代码就是我改过以后得。 直接就放到组件里就行。要是不出来的话,可能是你们插件有问题。可以重新安装一次插件。 template     div class=\\\"chart-box\\\" ref=\\\"chartBox\\\"         div class=\\\"chart-body\\\" ref=\\\"divPlugin\\\" id=\\\"divPlu

    2024年02月20日
    浏览(27)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包