-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stream not terminated properly by FFMpeg.stop (on Windows) #35
Comments
Having the same issue. What file did you modify? I can't find the syntax you have above in any of the ffmpeg files. |
Which file did you modify? Can you post a quick tutorial? |
fix(#35): graceful ffmpeg shutdown, update rtsp streams for the examples
Oh! Totally forgot about this issue, I don't know why I missed it out, my bad... |
In my program, I have buttons to start and stop a "preview" of the selected camera. The first time previewing is run, the stream loads fine --
ffmpeg
starts up, receives the data, and retransmits it to my NodeJS program in a format it can understand.However, if I then stop the stream:
...and then start a new stream within about 30 seconds, that second stream fails to load.
Camera model: Reolink C2 (https://www.amazon.com/gp/product/B01LS71KNO)
I did a variety of additional tests to try to narrow down what the problem was.
Some observations:
FFMpeg.stop()
was called, allffmpeg
streams from my network camera would fail for the next ~30 seconds -- including externalffmpeg
launches from cmd, which just write to a file.ffmpeg
instances. (rather than being preceded by a stream for whichFFMpeg.stop()
is called)So what are the errors that occur in the
ffmpeg
process, specifically?Well, lots of lines like this:
Anyway, observations 3 and 4 were interesting, as they seemed to indicate that the problem was a failure of
rtsp-ffmpeg
to properly close down the stream or something.And indeed, that is what I found. After hours of debugging, I finally figured out how to fix the issue:
With the change above, the function still causes the process to close, but apparently it does it more "gracefully" -- allowing the
ffmpeg
process to do some cleanup which is apparently required for an RTSP stream (over TCP), in order for the subsequent stream to not have issues.I've confirmed that the fix above is what solves the issue for me. Though keep in mind that I'm on Windows, so perhaps this issue doesn't show up on other platforms. But in any case, it was a super annoying bug, which I'm hoping can get fixed in this repo so others won't have to hit it.
Some posts by another user (and others) who seem to have hit the same issue:
Old bug ticket for ffmpeg, which seems somewhat similar but for the UDP protocol, and fixed years ago: (not that relevant solution-wise, but similar symptoms)
EDIT: I forgot that you also have to comment out the part below, otherwise the library spawns a new
ffmpeg
process after the first one gracefully exits (and then when the parent program exits, the second ffmpeg instance abruptly exits, causing the same problem -- just at a later point):The text was updated successfully, but these errors were encountered: