I refer back to my question here. I have a surveillance system which streams RTSP streams to my PC and records them using VLC,
How to close VLC gracefully using C#
I close VLC every half an hour and restart it so that it records files which are of 30 minutes length.
The VLC command looks like this,
vlc rtsp://*username*:*password*@192.168.1.60:554/ch01/0 --qt-start-minimized --sout=#transcode{ab=128,channels=2,samplerate=44100,scodec=none}:file{dst=D:\CCTV\Concord\2019_05_24\2019-05-24_2111_C1.mp4,no-overwrite}
The problem now is that sometimes the stream gets interrupted before the 30 minutes is up, and VLC will stop recording. This appears to be a network problem of some kind.
When this occurs VLC will continue running, but shows no network activity in task manager, and doesn't record anything.
How can I get VLC to either exit, or retry in this situation? Otherwise how can I detect this situation? If I can detect then I can close and restart VLC.
I used this log option on VLC and ran it for a day,
--file-logging --log-verbose=3 --logmode=text --logfile=blah
The log files end up with something like this in them typically,
main debug: adding a new sout input for `hevc` (sout_input: 0384ac70)
stream_out_transcode debug: not transcoding a stream (fcc=`hevc')
main debug: adding a new input
mp4 warning: Missing frame rate for stream 0, assuming 25fps
mp4 debug: adding input
main debug: Buffering 9%
main debug: Buffering 51%
main debug: Buffering 55%
main debug: Buffering 63%
main debug: Buffering 71%
main debug: Buffering 83%
main debug: Buffering 91%
main debug: Buffering 95%
main debug: Stream buffering done (1030 ms in 655 ms)
main debug: Decoder wait done in 0 ms
mp4 warning: i_length <= 0
live555 warning: no data received in 10s, eof ?
main debug: EOF reached
main debug: waiting decoder fifos to empty
live555 error: keep-alive failed: recvfrom() error: An existing connection was forcibly closed by the remote host
main debug: killing decoder fourcc `hevc'
main debug: removing module "hevc"
main debug: removing a sout input (sout_input: 0384ac70)
mp4 debug: tk 1 elst media time 0 duration 108539273 offset 0
mp4 debug: removing input
main warning: no more input streams for this mux
main debug: removing module "live555"
main debug: Program doesn't contain anymore ES
main debug: dead input
main debug: destroying useless sout
main debug: destroying chain... (name=transcode)
main debug: removing module "stream_out_transcode"
main debug: destroying chain done
main debug: destroying chain... (name=file)
main debug: removing module "stream_out_standard"
main debug: removing module "mp4"
mp4 debug: Close
Taking note of this specifically,
live555 warning: no data received in 10s, eof ?
main debug: EOF reached
main debug: waiting decoder fifos to empty
live555 error: keep-alive failed: recvfrom() error: An existing connection was forcibly closed by the remote host
All of that log can be seen here,
https://www.dropbox.com/s/e4b3e8jesrl08n3/2019-05-27_1622_C4.log?dl=0
UPDATE:
I have been experimenting with libvlc which does give me plenty more control. However what I am seeing doesn't seem to be firing the EndReached or EncounteredError events.
What I have tried instead is looking at the log messages that are coming through as there is a log event. It's a bit weak, but it seems to be the only way. I am looking for the following being written to the log,
- Retry. As soon as it tries to do a retry it gets into a retry loop and never ends. So I just kill it then and restart. I should look into how I can suppress the retry.
- An existing connection was forcibly closed by the remote host. But perhaps by looking for this and stopping, I am stopping it prior to it reaching the EncounteredError or EndReached event
I am getting there and it is working much better. I almost need to write a simple console app that just connects, and logs when each event occurs so that I can get the full picture in a simple way rather than going for the final solution. However it takes time as these occurrences of disconnects and failures only happen some of the time.