我正试图使用node-media-server来发布MPEG-DASH(或HLS)流,以供我们的应用客户在不同的网络、带宽和分辨率下使用。
我们的目标是尽可能接近实时,这样您就可以立即监控后院发生的情况。
已经完成的技术流程如下:
ffmpeg process on our server processes the incoming camera stream (separate child process for each camera) and publishes the stream via RTSP on the local machine for node-media-server to use as an 'input' (we are also saving segmented files, generating thumbnails, etc.). the ffmpeg command responsible for that is:
-c:v libx264 -preset ultrafast -tune zerolatency -b:v 900k -f flv rtmp://127.0.0.1:1935/live/office
node-media-server is running with what I found as the default configuration for 'live-streaming'
private NMS_CONFIG = { server: { secret: 'thisisnotmyrealsecret', }, rtmp_server: { rtmp: { port: 1935, chunk_size: 60000, gop_cache: false, ping: 60, ping_timeout: 30, }, http: { port: 8888, mediaroot: './server/media', allow_origin: '*', }, trans: { ffmpeg: '/usr/bin/ffmpeg', tasks: [ { app: 'live', hls: true, hlsFlags: '[hls_time=2:hls_list_size=3:hls_flags=delete_segments]', dash: true, dashFlags: '[f=dash:window_size=3:extra_window_size=5]', }, ], }, },
};
As I understand it, out of the box NMS (node-media-server) publishes the input stream it gets in multiple output formats: flv, mpeg-dash, hls. with all sorts of online players for these formats I'm able to access and the stream using the url on localhost. with mpeg-dash and hls I'm getting anything between 10-15 seconds of delay, and more.
我的目标是实现一个本地客户端的MPEG-DASH播放器,使用dash.js,并将其配置为尽可能接近实时。
我编写了以下代码:
<!doctype html>
<html>
<head>
<title>Dash.js Rocks</title>
<style>
video {
width: 640px;
height: 480px;
}
</style>
</head>
<body>
<div>
<video autoplay="" id="videoPlayer" controls=""></video>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dashjs/3.0.2/dash.all.min.js"></script>
<script>
(function(){
// var url = "https://dash.akamaized.net/envivio/EnvivioDash3/manifest.mpd";
var url = "http://localhost:8888/live/office/index.mpd";
var player = dashjs.MediaPlayer().create();
// config
targetLatency = 2.0; // Lowering this value will lower latency but may decrease the player's ability to build a stable buffer.
minDrift = 0.05; // Minimum latency deviation allowed before activating catch-up mechanism.
catchupPlaybackRate = 0.5; // Maximum catch-up rate, as a percentage, for low latency live streams.
stableBuffer = 2; // The time that the internal buffer target will be set to post startup/seeks (NOT top quality).
bufferAtTopQuality = 2; // The time that the internal buffer target will be set to once playing the top quality.
player.updateSettings({
'streaming': {
'liveDelay': 2,
'liveCatchUpMinDrift': 0.05,
'liveCatchUpPlaybackRate': 0.5,
'stableBufferTime': 2,
'bufferTimeAtTopQuality': 2,
'bufferTimeAtTopQualityLongForm': 2,
'bufferToKeep': 2,
'bufferAheadToKeep': 2,
'lowLatencyEnabled': true,
'fastSwitchEnabled': true,
'abr': {
'limitBitrateByPortal': true
},
}
});
console.log(player.getSettings());
setInterval(() => {
console.log('Live latency= ', player.getCurrentLiveLatency());
console.log('Buffer length= ', player.getBufferLength('video'));
}, 3000);
player.initialize(document.querySelector("#videoPlayer"), url, true);
})();
</script>
</body>
</html>
通过在线测试视频 (https://dash.akamaized.net/envivio/EnvivioDash3/manifest.mpd),我发现直播延迟值接近2秒(但我无法实际确认。它是一个视频文件流。在我的办公室里,我有一个摄像头,所以我可以比较现实生活和我的视频流之间的延迟)。 然而,在本地使用我的NMS时,似乎这个值不想低于20-25秒。
我做错了什么吗?客户端HTML上是否有任何配置我忘记了? 还是我应该在服务器端(NMS)添加缺少的配置?