【使用webrtc-streamer分析rtsp视频流】

打印 上一主题 下一主题

主题 518|帖子 518|积分 1554

webrtc-streamer



  • WebRTC (Web Real-Time Communications) 是一项实时通讯技能,它答应网络应用大概站点,在不借助中间前言的情况下,建立浏览器之间点对点(Peer-to-Peer)的毗连,实现视频流和(或)音频流大概其他恣意数据的传输。WebRTC 包含的这些尺度使用户在无需安装任何插件大概第三方的软件的情况下,创建点对点(Peer-to-Peer)的数据分享和电话聚会会议成为大概。
    1. 简单的说:WebRTC 是一种 HTML5规范,他无需在浏览器中安装任何插件可以在网页内进行实时通信工作的开源技术,它直接在浏览器和设备之间添加实时媒体通信。
    复制代码
  • rtsp(Real Time Streaming Protocol,RTSP)是实时视频网络传输主流的实现方式,是一种网络流媒体协议。低延时高清晰度的RTSP视频传播输是网络直播、在线聚会会议体系等行业的核心技能。
  • webrtc-streamer是一个使用简朴机制通过 WebRTC 流式传输视频捕获装备和 RTSP 源的项目,它内置了一个小型的 HTTP server 来对 WebRTC需要的相干接口提供支持。
使用方法

1、下载webrtc-streamer

  1. https://github.com/mpromonet/webrtc-streamer/releases
复制代码
2、运行

  1. 双击解压后的.exe文件运行,默认抛出本机8000端口(172.0.0.1:8000)
复制代码


  • 由于 webrtc 的核心库还不支持H265的视频编码,以是要配置装备视频编码方式为H264
  • 下令:-o ,默认情况video会举行编码、解码,占用资源,大概导致cpu拉满,使用-o将取消编码解码
  • 自定义端口:创建.bat文件,并双击实行,文件内容如下:
    1. @echo off
    2. start "" ".\webrtc-streamer.exe"  -H 0.0.0.0:9998 -o
    3. exit
    复制代码
  • 运行乐成后,可在浏览器中查询所有api
    1. //192.168.3.33:9998/api/help
    2. http: [
    3.   '/api/addIceCandidate',
    4.   '/api/call',
    5.   '/api/createOffer',
    6.   '/api/getAudioDeviceList',
    7.   '/api/getAudioPlayoutList',
    8.   '/api/getIceCandidate',
    9.   '/api/getIceServers',
    10.   '/api/getMediaList',
    11.   '/api/getPeerConnectionList', // 判断当前的webrtc-streamer正在连接的通道
    12.   '/api/getStreamList',
    13.   '/api/getVideoDeviceList',
    14.   '/api/hangup',
    15.   '/api/help',
    16.   '/api/log',
    17.   '/api/setAnswer',
    18.   '/api/version',
    19.   '/api/whep'
    20. ]
    复制代码
3、引用开发包



  • 将下载包html文件夹下webrtcstreamer.js文件和html/libs文件夹下adapter.min.js文件复制到VUE项目public目录下 、在index.html文件里引入这两个js文件
    1. <head>
    2.   <!-- rtsp -->
    3.   <script src="/data/webrtcstreamer.js" charset="utf-8"></script>
    4.   <script src="/data/adapter.min.js" charset="utf-8"></script>
    5. </head>
    复制代码
4、页面中使用

  1. <template>
  2.   <div class="ev-player">
  3.     <CommonDragWindow v-model="innerShow" :width="600" :height="400" :resize="true" :position="position">
  4.       <template v-slot:title>{{ title }}</template>
  5.       <template #default>
  6.         <video :id="`video-${equipId}`" autoplay width="100%" height="98%"></video>
  7.       </template>
  8.     </CommonDragWindow>
  9.   </div>
  10. </template>
  11. <script setup>
  12.   import CommonDragWindow from './CommonDragWindow.vue'
  13.   import { getConfigList } from '@/api/common.js'
  14.   import { ref, onMounted, watchEffect, watch, nextTick } from 'vue'
  15.   const show = defineModel({ type: Boolean, default: false })
  16.   const props = defineProps({
  17.     title: {
  18.       type: String,
  19.       default: '监控视频'
  20.     },
  21.     equipId: {
  22.       type: [Number, String]
  23.     }
  24.   })
  25.   const innerShow = ref(false)
  26.   const position = ref({
  27.     top: 500,
  28.     left: 20
  29.   })
  30.   let webRtcServer = null
  31.   watchEffect(() => {
  32.     innerShow.value = show.value
  33.   })
  34.   watch(
  35.     () => innerShow.value,
  36.     async (val) => {
  37.       if (val) {
  38.         const rtspStr = 'rtsp://132.239.12.145:554/axis-media/media.amp'
  39.         if (rtspStr) {
  40.           await nextTick() // 待dom加载完毕
  41.           let videoDocument = document.getElementById('video')
  42.           webRtcServer = new WebRtcStreamer(videoDocument, `http://${window.appConfig.localhost}:8000`)
  43.           webRtcServer.connect(rtspStr, null, `rtptransport=tcp&timeout=60`)
  44.         }
  45.       } else {
  46.         webRtcServer?.disconnect()
  47.         webRtcServer = null
  48.       }
  49.       show.value = val
  50.     }
  51.   )
  52.   onMounted(() => {})
  53. </script>
  54. <style scoped lang="scss">
  55.   .ev-player {
  56.     :deep(video) {
  57.       width: 100%;
  58.       height: calc(100% - 5px);
  59.     }
  60.   }
  61. </style>
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

天津储鑫盛钢材现货供应商

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表