illuspas / Node-Media-Server

A Node.js implementation of RTMP/HTTP-FLV/WS-FLV/HLS/DASH/MP4 Media Server
https://www.npmjs.com/package/node-media-server
MIT License
5.89k stars 1.51k forks source link

HLS/m3u8 target duration unstable #596

Open hankthetank27 opened 1 year ago

hankthetank27 commented 1 year ago

I've recently been experiencing an issue where my the TARGETDURATION property on my index.m3u8 playlist changes quite dramatically at infrequent but seemingly random times. My application as a single infinitely running HLS stream which has audio files piped into into it sequentially, like a radio broadcast. In my NMS config file, I have my HLS time set to 3 seconds, but occasionally will jump up to large values over 3000 seconds at times, causing the stream to go silent (often these values are longer than a single song itself). I'm having a lot of trouble diagnosing if this a bug in NMS itself. I'm not very well versed on how HLS works, and after some research have not been able to determine if this is normal behavior, although it seems like it wouldn't be. Below is my NMS config file:

  const config = {
    logType: 3,
    rtmp: {
      port: 1935,
      chunk_size: 60000,
      gop_cache: false,
      ping: 60,
      ping_timeout: 120
    },
    http: {
      port: 8000,
      mediaroot: './media',
      allow_origin: '*'
    },
    trans: {
      ffmpeg: ffmpegPath,
      tasks: [
        {
          app: 'live',
          vc: "copy",
          vcParam: [],
          ac: "aac",
          acParam: ['-ab', '128k', '-ac', '2', '-ar', '44100'],
          rtmp:true,
          rtmpApp:'live2',
          hls: true,
          hlsFlags: '[hls_time=3:hls_list_size=4:hls_flags=delete_segments]',
          hlsKeep: false
        }
      ]
    },
    mediaServer: {
      idleTimeout: 30
    },
  };

And here is an example of an m3u8 file with the correct target duration vs one that is incorrect...

correct:

EXTM3U

EXT-X-VERSION:3

EXT-X-TARGETDURATION:3

EXT-X-MEDIA-SEQUENCE:2296

EXTINF:3.018889,

index2296.ts

EXTINF:2.995667,

index2297.ts

EXTINF:2.995667,

index2298.ts

EXTINF:2.995667,

index2299.ts

incorrect:

EXTM3U

EXT-X-VERSION:3

EXT-X-TARGETDURATION:3072

EXT-X-MEDIA-SEQUENCE:56864

EXTINF:0.023222,

index56864.ts

EXTINF:1944.791444,

index56865.ts

EXTINF:3072.300000,

index56866.ts

EXTINF:3072.300000,

index56867.ts