如何使用 C# 优雅地关闭 VLC [英] How to close VLC gracefully using C#

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

问题描述

我正在运行一个监控系统,并想将一些闭路电视摄像机的视频录制到我的电脑上.

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:CCTVConcord2019_05_242019-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.

我的代码就是这样做的,

My code does this,

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.

我尝试了其他方法 Close、Dispose,但它们不起作用.

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天全站免登陆