I am running a surveillance system, and wanting to record the video from some CCTV cameras to my PC.
I can get the recording to occur using the VLC command line 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}
However I want to stop and restart the recording every half an hour so that I get files small enough that I can use.
I wrote a C# application to do this, it simply kills all VLC processes and starts new ones. It is triggered by task scheduler on the half hour.
This works when I run normal VLC instances showing in the taskbar. However I want they to be out of the way in the system tray. I can do this by adding this VLC option,
--qt-start-minimized
Which runs it under background processes if I look in task manager.
My code does this,
foreach(Process process in Process.GetProcesses().Where(x => x.ProcessName == "vlc"))
{
Process.GetProcessById(id).CloseMainWindow();
}
However VLC no longer has a main window, so that doesn't work.
If I do this,
Process.GetProcessById(id).Kill();
The videos get corrupted because VLC doesn't exist gracefully.
I tried the other methods Close, Dispose, but they don't work.
It seems to me that I need to maximise these windows first before calling CloseMainWindow, or find some other way to exit them, or if there is an option in VLC to start a new file every half an hour?
"Kill is the only way to terminate processes that do not have graphical interfaces."
So basically, the only chance you have to make this work is to check if VLC process offers a way to control it while running in background: in this way, you could first stop the recording process and then kill the process.
I'm not aware of what functionalities it exposes, but You could do that with VLC HTTP interface or maybe check for some
dbus
commands?try invoking vlc commands using RC (Remote command) Interface. Documentation can be found here: https://wiki.videolan.org/documentation:modules/rc/ If you start vlc with the remote commands you can then send via websocked a command to stop the recording or close vlc.
Try adding to your command
The list of available commands are:
This question is similar to yours, and this specific answer explains why CTRLC is not the right way to close: VLC screen capture using terminal.
Example usage: http://sureskumar.com/RemoteVLC/#examples (Arduino code but easy to understand)
Thanks Norcino, your solution works well. I added in the options you mentioned,
Then my C# looks like this,
The VLC instances are completely running in the background.
Plus it has a try and catch block etc. Will do more testing, but so far works well.