环境搭建
docker pull alfg/nginx-rtmp
docker run -it \
-p 1935:1935 \
-p 8080:80 \
--name nginx-rtmp \
-h nginx-rtmp \
alfg/nginx-rtmp
推流
到这个网站 https://obsproject.com/ 下载 obs,并设置推流地址为:
rtmp://123.56.135.201:1935/stream
观看直播
代码放到web服务器下(不能放本地)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title></title>
<link
href="http://cdn.bootcss.com/video.js/6.0.0-RC.5/alt/video-js-cdn.min.css"
rel="stylesheet"
/>
</head>
<body>
<video
id="hls-video"
width="300"
height="200"
class="video-js vjs-default-skin"
playsinline
webkit-playsinline
autoplay
controls
preload="auto"
x-webkit-airplay="true"
x5-video-player-fullscreen="true"
x5-video-player-typ="h5"
>
<source
src="http://123.56.135.201:8080/live/_240p264kbs/index.m3u8"
type="application/x-mpegURL"
/>
</video>
<script src="http://cdn.bootcss.com/video.js/6.0.0-RC.5/video.js"></script>
<script src="http://cdn.bootcss.com/videojs-contrib-hls/5.3.3/videojs-contrib-hls.js"></script>
<script>
var player = videojs("hls-video");
player.play();
</script>
</body>
</html>