nginx 流媒体配置

windows中 nginx流媒体下载地址

通过网盘分享的文件:nginx-1.17-rtmp.rar

链接: https://pan.baidu.com/s/1_QbdfNsMz_fwc2xnlAUxkg 提取码: 5jqf

1、摄像头中配置流媒体转发

2、前端代码中播放流媒体vue2

html 复制代码
<template>
  <div class="stream-page">
    <div class="stream-toolbar">
      <div>
        <div class="stream-title">流媒体预览</div>
        <div class="stream-url">{{ streamUrl }}</div>
      </div>
      <el-button
        size="mini"
        type="primary"
        icon="el-icon-refresh"
        @click="reloadStream"
      >
        重新加载
      </el-button>
    </div>

    <div class="player-shell">
      <video
        ref="videoPlayer"
        class="stream-video"
        controls
        autoplay
        muted
        playsinline
      ></video>
      <div v-if="errorMessage" class="stream-error">
        {{ errorMessage }}
      </div>
    </div>
  </div>
</template>

<script>
import Hls from 'hls.js'

const STREAM_URL = 'http://192.168.0.174:8080/hls/camera231.m3u8'

export default {
  name: 'StreamMedia',
  data() {
    return {
      streamUrl: STREAM_URL,
      hls: null,
      errorMessage: ''
    }
  },
  mounted() {
    this.initPlayer()
  },
  beforeDestroy() {
    this.destroyPlayer()
  },
  methods: {
    initPlayer() {
      const video = this.$refs.videoPlayer
      if (!video) {
        return
      }

      this.errorMessage = ''
      this.destroyPlayer()
      video.pause()
      video.removeAttribute('src')
      video.load()

      if (Hls.isSupported()) {
        const hls = new Hls({
          liveSyncDurationCount: 3,
          maxLiveSyncPlaybackRate: 1.5
        })

        this.hls = hls
        hls.loadSource(this.streamUrl)
        hls.attachMedia(video)
        hls.on(Hls.Events.MANIFEST_PARSED, () => {
          video.play().catch(() => {})
        })
        hls.on(Hls.Events.ERROR, (event, data) => {
          if (!data.fatal) {
            return
          }

          if (data.type === Hls.ErrorTypes.NETWORK_ERROR) {
            hls.startLoad()
            return
          }

          if (data.type === Hls.ErrorTypes.MEDIA_ERROR) {
            hls.recoverMediaError()
            return
          }

          this.errorMessage = '视频流播放失败,请确认推流和 HLS 地址是否正常。'
          this.destroyPlayer()
        })
        return
      }

      if (video.canPlayType('application/vnd.apple.mpegurl')) {
        video.src = this.streamUrl
        video.play().catch(() => {})
        return
      }

      this.errorMessage = '当前浏览器不支持 HLS 播放。'
    },
    reloadStream() {
      this.initPlayer()
    },
    destroyPlayer() {
      if (this.hls) {
        this.hls.destroy()
        this.hls = null
      }
    }
  }
}
</script>

<style scoped lang="scss">
.stream-page {
  min-height: calc(100vh - 84px);
  padding: 16px;
  background: #f3f6f8;
}

.stream-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.stream-title {
  color: #1f2d3d;
  font-size: 18px;
  font-weight: 600;
  line-height: 28px;
}

.stream-url {
  color: #606266;
  font-size: 13px;
  line-height: 20px;
  word-break: break-all;
}

.player-shell {
  position: relative;
  width: 100%;
  height: calc(100vh - 160px);
  min-height: 420px;
  overflow: hidden;
  background: #111820;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
}

.stream-video {
  display: block;
  width: 100%;
  height: 100%;
  background: #111820;
}

.stream-error {
  position: absolute;
  right: 16px;
  bottom: 16px;
  max-width: calc(100% - 32px);
  padding: 8px 12px;
  color: #f56c6c;
  font-size: 13px;
  line-height: 20px;
  background: rgba(0, 0, 0, 0.72);
  border-radius: 4px;
}
</style>
相关推荐
tz52516 小时前
Superpowers 游戏开发实战应用场景大纲
linux·运维·服务器
倔强的石头_16 小时前
Linux 电脑也能被 UU 远程连进去了:Linux PC 端内测上手,主控和被控我都试了
运维
Decay__20 小时前
PostgreSQL WAL 归档与时间点恢复 —— WAL 连续归档、recovery_target 时点恢复与 pg_rewind
运维·数据库·sql·postgresql
Decay__1 天前
PostgreSQL 索引与 SQL 优化 —— B-tree、GiST、GIN、BRIN、执行计划与索引设计实战
运维·数据库·sql·postgresql
JWIPC1 天前
MyClaw 3.0 自动化数据采集实战指南
linux·运维·笔记·科技·深度学习·物联网·自动化
Kainy1 天前
生产服务器从机械盘迁移NVMe固态:旧盘不动、退路先行的六步实操全记录
运维·服务器
Henry-SAP1 天前
SAP BOM项目类别详解——L/T/R/N各类目的业务含义解析
运维
op_qo1 天前
写了几年 OpenResty Lua 网关脚本,聊聊绕不开的 5 个痛点与一种新解法
nginx
天空属于哈夫克31 天前
企业微信二次开发:解锁更多自动化应用场景
运维·自动化·企业微信
Diligently_1 天前
第 08 篇|单机部署:本地安装与 Docker 最佳实践
运维·spring boot·docker