页面效果:
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FLV Player</title>
</head>
<script src="https://cdn.bootcss.com/flv.js/1.6.2/flv.js"></script>
<!-- <script src="https://unpkg.com/flv.js@1.6.2/dist/flv.js"></script> -->
<body>
<div style='margin-bottom:6px'>
<input id='flvUrl' style='width:545px' value="http://waketzheng.top:8080/live/0.live.flv"></input>
<button id='flvBtn'>Play</button>
</div>
<div>
<video id="vVideo" width="600" height="500" controls />
</div>
<script>
function playFlv(url) {
if (flvjs.isSupported()) {
// 原生H5支持的媒体格式主要有MP4、OGG、WebM、M3U8
var videoElement = document.getElementById('vVideo');
var flvPlayer = flvjs.createPlayer({
url,
type: 'flv',
isLive: false,
hasAudio: false,
hasVideo: true,
enableStashBuffer: false,
changeOrigin: true
});
flvPlayer.attachMediaElement(videoElement);
flvPlayer.load();
flvPlayer.play();
}
}
document.getElementById("flvBtn").addEventListener('click', function(){
playFlv(document.getElementById('flvUrl').value);
}, false);
</script>
</body>
</html>
=======================================================================
附:
服务端推流使用的是如下命令
docker pull zlmediakit/zlmediakit:master
docker run -id -p 1937:1935 -p 8080:80 -p 8443:443 -p 554:554 -p 8111:8000/udp zlmediakit/zlmediakit:master
ffmpeg -rtsp_transport tcp -probesize 32 -analyzeduration 5000000 -i "rtsp://waketzheng.top/live/test" -an -c:v libx264 -tune zerolatency -preset ultrafast -b:v 1000k -r 30 -g 15 -c:a aac -f flv "rtmp://127.0.0.1:1937/live/0"