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>
相关推荐
虎头金猫5 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
还是大剑师兰特5 天前
解决nginx错误:http://localhost:7000正常,http://localhost:7000/map 报错404
nginx·大剑师
AI职业加油站5 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
此冬歌咏5 天前
K8s 节点故障实战:优雅驱逐 31 秒,硬故障 331 秒,以及那个永远 Pending 的 Pod
运维·k8s
xing-xing5 天前
Docker容器中Nginx站点根目录网页配置访问
nginx·docker
-梅5 天前
linux(8) 软硬链接
linux·运维·服务器
张洛闻Eren5 天前
k8s云原生【第十课】:水平 Pod 自动扩缩容
运维·数据库·云原生·kubernetes·github
其实防守也摸鱼5 天前
内网穿透与反向代理:原理、工具与实战指南
android·大数据·运维·安全·网络安全·自动化·渗透
布裘5 天前
【银河麒麟】V4桌面图标消失,右击鼠标没反应排查
运维·银河麒麟·桌面环境
懂软件的胡子个哥5 天前
微信机器人为什么需要“回复候选”而不是所有 AI 内容直接发送
运维·微信·自动化·wechatapi·个人微信号二次开发