如何使用C#正常关闭VLC [英] How to close VLC gracefully using C#

查看:701
本文介绍了如何使用C#正常关闭VLC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行监视系统,并希望将一些CCTV摄像机的视频录制到我的PC中。

I am running a surveillance system, and wanting to record the video from some CCTV cameras to my PC.

我可以使用VLC命令进行录制

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.

我编写了一个C#应用程序来执行此操作,它只是杀死了所有VLC进程并开始了新的进程。它由任务调度程序在半小时内触发。

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.

当我运行任务栏中显示的正常VLC实例时,此方法有效。但是,我希望它们不会妨碍系统托盘的放置。我可以通过添加此VLC选项来做到这一点,

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.

我的代码为此,

foreach(Process process in Process.GetProcesses().Where(x => x.ProcessName == "vlc"))
{
    Process.GetProcessById(id).CloseMainWindow();
}

但是VLC不再有主窗口,因此无法使用。

However VLC no longer has a main window, so that doesn't work.

如果我这样做,

Process.GetProcessById(id).Kill();

由于VLC不存在,视频被损坏。

The videos get corrupted because VLC doesn't exist gracefully.

我尝试了其他方法关闭,处置,但它们不起作用。

I tried the other methods Close, Dispose, but they don't work.

在我看来,我需要先最大化这些窗口调用CloseMainWindow,或者找到其他方法退出它们,或者在VLC中是否存在每半小时启动一个新文件的选项?

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?

推荐答案

尝试使用RC(远程命令)接口调用vlc命令。
文档可以在这里找到: https://wiki.videolan.org/documentation :modules / rc /
如果您使用远程命令启动vlc,则可以通过websocked发送命令以停止录制或关闭vlc。

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.

尝试添加到命令中


-intf rc --rc-host = my-ip:my-port- rc-quiet --rc-extend

--intf rc --rc-host="my-ip:my-port" --rc-quiet --rc-extend

可用命令列表为:

longhelp
+----[ Remote control commands ]
|
| add XYZ  . . . . . . . . . . . . add XYZ to playlist
| enqueue XYZ  . . . . . . . . . queue XYZ to playlist
| playlist . . . . .  show items currently in playlist
| play . . . . . . . . . . . . . . . . . . play stream
| stop . . . . . . . . . . . . . . . . . . stop stream
| next . . . . . . . . . . . . . .  next playlist item
| prev . . . . . . . . . . . .  previous playlist item
| goto . . . . . . . . . . . . . .  goto item at index
| repeat [on|off] . . . .  toggle playlist item repeat
| loop [on|off] . . . . . . . . . toggle playlist loop
| random [on|off] . . . . . . .  toggle random jumping
| clear . . . . . . . . . . . . . . clear the playlist
| status . . . . . . . . . . . current playlist status
| title [X]  . . . . . . set/get title in current item
| title_n  . . . . . . . .  next title in current item
| title_p  . . . . . .  previous title in current item
| chapter [X]  . . . . set/get chapter in current item
| chapter_n  . . . . . .  next chapter in current item
| chapter_p  . . . .  previous chapter in current item
|
| seek X . . . seek in seconds, for instance `seek 12'
| pause  . . . . . . . . . . . . . . . .  toggle pause
| fastforward  . . . . . . . .  .  set to maximum rate
| rewind  . . . . . . . . . . . .  set to minimum rate
| faster . . . . . . . . . .  faster playing of stream
| slower . . . . . . . . . .  slower playing of stream
| normal . . . . . . . . . .  normal playing of stream
| f [on|off] . . . . . . . . . . . . toggle fullscreen
| info . . . . .  information about the current stream
| stats  . . . . . . . .  show statistical information
| get_time . . seconds elapsed since stream's beginning
| is_playing . . . .  1 if a stream plays, 0 otherwise
| get_title . . . . .  the title of the current stream
| get_length . . . .  the length of the current stream
|
| volume [X] . . . . . . . . . .  set/get audio volume
| volup [X]  . . . . . . .  raise audio volume X steps
| voldown [X]  . . . . . .  lower audio volume X steps
| adev [X] . . . . . . . . . . .  set/get audio device
| achan [X]. . . . . . . . . .  set/get audio channels
| atrack [X] . . . . . . . . . . . set/get audio track
| vtrack [X] . . . . . . . . . . . set/get video track
| vratio [X]  . . . . . . . set/get video aspect ratio
| vcrop [X]  . . . . . . . . . . .  set/get video crop
| vzoom [X]  . . . . . . . . . . .  set/get video zoom
| snapshot . . . . . . . . . . . . take video snapshot
| strack [X] . . . . . . . . . set/get subtitles track
| key [hotkey name] . . . . . .  simulate hotkey press
| menu . . [on|off|up|down|left|right|select] use menu
|
| @name marq-marquee  STRING  . . overlay STRING in video
| @name marq-x X . . . . . . . . . . . .offset from left
| @name marq-y Y . . . . . . . . . . . . offset from top
| @name marq-position #. . .  .relative position control
| @name marq-color # . . . . . . . . . . font color, RGB
| @name marq-opacity # . . . . . . . . . . . . . opacity
| @name marq-timeout T. . . . . . . . . . timeout, in ms
| @name marq-size # . . . . . . . . font size, in pixels
|
| @name logo-file STRING . . .the overlay file path/name
| @name logo-x X . . . . . . . . . . . .offset from left
| @name logo-y Y . . . . . . . . . . . . offset from top
| @name logo-position #. . . . . . . . relative position
| @name logo-transparency #. . . . . . . . .transparency
|
| @name mosaic-alpha # . . . . . . . . . . . . . . alpha
| @name mosaic-height #. . . . . . . . . . . . . .height
| @name mosaic-width # . . . . . . . . . . . . . . width
| @name mosaic-xoffset # . . . .top left corner position
| @name mosaic-yoffset # . . . .top left corner position
| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets
| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment
| @name mosaic-vborder # . . . . . . . . vertical border
| @name mosaic-hborder # . . . . . . . horizontal border
| @name mosaic-position {0=auto,1=fixed} . . . .position
| @name mosaic-rows #. . . . . . . . . . .number of rows
| @name mosaic-cols #. . . . . . . . . . .number of cols
| @name mosaic-order id(,id)* . . . . order of pictures
| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio
|
| help . . . . . . . . . . . . . . . this help message
| longhelp . . . . . . . . . . . a longer help message
| logout . . . . . . .  exit (if in socket connection)
| quit . . . . . . . . . . . . . . . . . . .  quit vlc
|
+----[ end of help ]

此问题与您的问题相似,这个特定的答案说明了为什么CTRLC不是正确的关闭方法:使用终端进行VLC屏幕捕获

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.

示例用法: http:// sureskumar.com/RemoteVLC/#examples (Arduino代码,但易于理解)

Example usage: http://sureskumar.com/RemoteVLC/#examples (Arduino code but easy to understand)

这篇关于如何使用C#正常关闭VLC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆