rtsp转h5播放

  1. 服务器安装ffmpeg到e:\ffmpeg,设置PATH

  2. 安装node.js

  3. 下载websocket-relay.js到e:\zhibo 下载地址

  4. e:\zhibo\npm install ws,注意不要用-g参数安装全局

  5. e:\zhibo\node websocket.js supersecret 8081 8812
    8081会交给ffmpeg传输数据,8812用来提供http流服务

  6. 把串流进行转换,可以转换多个,每个cmd窗口打开一个:
    ffmpeg -i “rtsp://admin:[email protected]:554/h264/ch1/sub/av_stream” -q 0 -f mpegts -codec:v mpeg1video -s 704x578 http://127.0.0.1:8081/supersecret/camra_1

ffmpeg -i “rtsp://admin:[email protected]:554/h264/ch1/sub/av_stream” -q 0 -f mpegts -codec:v mpeg1video -s 704x578 http://127.0.0.1:8081/supersecret/camra_2
用的是sub子码流,主码流把sub换成main

  1. jsmpeg.min.js放到web服务器上,h5嵌入代码:
<canvas id="video-canvas1">canvas>	
<canvas id="video-canvas2">canvas>	
	<script type="text/javascript" src="jsmpeg.min.js">script>
	<script type="text/javascript">
		var canvas1 = document.getElementById('video-canvas1');
		var url1 = 'ws://'+document.location.hostname+':8812/live1';
		var player1 = new JSMpeg.Player(url1, {canvas: canvas1});
		
		var canvas2 = document.getElementById('video-canvas2');
		var url2= 'ws://'+document.location.hostname+':8812/live2';
		var player2 = new JSMpeg.Player(url2, {canvas: canvas2});		
	script>

访问即可。

你可能感兴趣的:(前端)