rtsp-relay icon indicating copy to clipboard operation
rtsp-relay copied to clipboard

Stream hangs after ~20 seconds

Open computerjazz opened this issue 4 years ago • 4 comments

Thank you for an amazing library! Over the last few weeks I've spent so many hours tinkering with ffmpeg/vlc options trying to pipe a Wyze cam feed into a browser and this works so much better than anything I was able to cobble together.

I'm running into one issue though. After some amount of time the stream just...stops. I'm not getting any error messages either -- it's as if the spawned process is just hanging indefinitely.

If I don't pass any additionalOptions I get about 20 seconds in before it hangs, but if I pass the following options I get about 1:30, so maybe I'm hitting some ffmpeg limit?

  additionalFlags: [
    "-s", "960x540",
    "-an",
    "-b:v", "500k",
    "-fflags", "nobuffer",
  ]

Any ideas? Thank you!

Possibly related: https://stackoverflow.com/questions/37166775/after-10m-ffmpeg-stops-saving-video-on-nodejs

computerjazz avatar Feb 10 '20 05:02 computerjazz

Update — I addd some listeners here:

https://github.com/k-yle/rtsp-relay/blob/master/index.js#L34

    this.stream.stderr.on('data', () => console.log('err data'))
    this.stream.stderr.on('error', (e) => console.log('err err', e))

It's been running fine for several minutes now 🤞 I am getting some errors logged out, but the feed seems fine. So, maybe some internal buffer is filling up? https://stackoverflow.com/questions/22693773/node-ffmpeg-child-process-stops-but-still-alive

computerjazz avatar Feb 10 '20 05:02 computerjazz

Interesting - It works fine for me on windows but I'll admit I've never tried more than 5mins or so at a time.

We basically pipe streamIn.stdout to ws.send - if anything is reaching a limit it'll be around that bit.

tbh piping this volume of data isn't something node.js was designed for and a lower level solution is probably the way to go... its something I've been meaning to experiment with when I get a chance

k-yle avatar Feb 11 '20 07:02 k-yle

Hi, I had the same problem: I fixed it by lowering the log levels: additionalFlags: ['-s','320x180', '-loglevel','error'], => It's being running for hours now

Note @k-yle : I had to change

 this.stream = spawn(
      'ffmpeg',
      [
        '-i',
        url,
        '-f',
        'mpegts',
        '-codec:v',
        'mpeg1video',
        '-r',
        '30', // 30 fps. any lower and the client can't decode it
        ...additionalFlags,
        '-',
      ],
      { detached: false},
    );

patricerosay avatar Mar 17 '20 16:03 patricerosay

@patricerosay I published a fix yesterday (v1.0.3) based on the previous comments in this thread - PRs welcome if you've got further improvements (:

k-yle avatar Mar 18 '20 07:03 k-yle