hb + nginx_rtmp模块 + hls.js

博客提及了HTML和Nginx相关内容,HTML是前端开发常用技术,Nginx常用于后端服务器运维。这些信息技术在网页构建和服务部署中发挥重要作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


<!DOCTYPE html>
<html>
	<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
	<title>Video Example</title>
	<script type="text/javascript">
var pusher = null;
// H5 plus事件处理
function plusReady(){
	// 创建直播推流控件
	pusher = new plus.video.LivePusher('pusher',{
		url:'rtmp://xxxx:1935/src/xxxx'
	});
	// 监听状态变化事件
	pusher.addEventListener('statechange', function(e){
		console.log('statechange: '+JSON.stringify(e));
	}, false);
}
document.addEventListener('plusready', plusReady, false);
// 开始推流
function startPusher() {
	pusher.start();
}
	</script>
	</head>
	<body style="margin:0;padding:0;text-align:center;">
		直播推流控件
		<br/><br/>
		<button onclick="startPusher()">开始</button>
		<br/><br/>
		<div id="pusher" style="width:100%;height:300px;background-color:#000000;margin:auto"></div>
	</body>
</html>

hb

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
		<video id="video"></video>
		<script>
		  var video = document.getElementById('video');
		  if(Hls.isSupported()) {
		    var hls = new Hls();
		    hls.loadSource('http://xxxx/360p/xxxx.m3u8');
		    hls.attachMedia(video);
		    hls.on(Hls.Events.MANIFEST_PARSED,function() {
		      video.play();
		  });
		 }
		  else if (video.canPlayType('application/vnd.apple.mpegurl')) {
		    video.src = 'http://xxxx/360p/xxxx.m3u8';
		    video.addEventListener('loadedmetadata',function() {
		      video.play();
		    });
		  }
		</script>

	</body>
	
</html>

html

nginx

server{
        listen 8887;
        server_name xxx.xxx.xxx;
        root /web/myMp4;
        location /{
                add_header Access-Control-Allow-Origin *;
                add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
                add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
        }

}
rtmp {

    server {

        listen 1935;  #监听的端口

        chunk_size 4000;

application src {
    live on;
    #exec_push ffmpeg -i rtmp://xxxxxxx:1935/src/$name -f flv rtmp://localhost/hls/$name 2>>/web/myMp4/ffmpeg-$name.log;
    #exec ffmpeg -re -i rtmp://localhost:1935/src/$name -vcodec flv -acodec copy -s 640x320 -f flv rtmp://localhost:1935/360p/$name 2>>/web/myMp4/ffmpeg-$name.log;
    exec ffmpeg -i rtmp://localhost:1935/src/$name -c:a copy -c:v libx264  -s 360x360 -f flv rtmp://localhost:1935/360p/$name 2>>/web/myMp4/ffmpeg-$name.log;
    hls on;
    hls_path /web/myMp4/allP;
    hls_fragment 5s;
}

application 360p {
    live on;
    hls on;
    hls_path /web/myMp4/360p;
    hls_fragment 5s;
}
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值