在 VLC 中录制 UDP 流的丑陋 hack。
Ugly hack for recording a UDP stream in VLC.
我最近不得不学习我生疏的编码知识来尝试创建一个简单的脚本来记录我们舞台摄像机的纪录片流,这样,就不必有人整天呆在身边并制定繁琐的录制时间表,您可以 运行 在调度程序中显示名称可执行文件,流将被记录、重命名并传输到可公开访问的文件夹。
我在录制方面遇到了一些问题,主要是确保脚本 运行s 时没有任何问题。最理想的情况是,计算机不需要 .setFocus 等选项来向 VLC 发送命令,因为,如果有人在 VLC 即将发送录制命令时取消选择 VLC 怎么办?
我在这里花了大约一周的时间进行研究后编写了这段代码,它非常简单,但我非常感谢所有关于如何优化它的反馈。显然,在我们找到专门的 api 程序员将东西与我们的硬件集成之前,这更像是一个 alpha 阶段,但我一直喜欢自动化任务。
import time, SendKeys, os
# Start VLC using a udp stream playlist file
from pywinauto.application import Application
app = Application().Start(
cmd_line=u'"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" '
u'--started-from-file "C:\Program Files (x86)\VideoLAN\VLC\udp.xspf"')
qwidget = app.QWidget
qwidget.Wait('ready')
qwidget.SetFocus()
time.sleep(3)
# Record for 9000 seconds = 2h30m
SendKeys.SendKeys("+r")
time.sleep(9000)
# Quit VLC, leaving a non-corrupted .ts video file
app.Kill_()
# Ugly hack code for renaming the file. The folder is supposedly empty given that the code, if successful in
# creating a file here, must also be successful in moving the same file to the final directory.
# File is renamed with camera name, show name and date and time for the recording.
# The original naming format for VLC is something like
# vlc-record-2015-11-16-08h59m01s-udp___xxx.xxx.xxx.xxx_xxxx-.ts
# (Optimally I'd like to change the file output format to mp4 or similar, but couldn't figure out
# a way to use both Start from Playlist file and --sout options in the command line interface.
os.chdir(r"C:/VLC")
# Necessary?
FileName = str(os.listdir("C:/VLC"))[2:59]
ShowName = str("Swanlake")
os.rename(FileName, "Scenbild " + ShowName + " " + FileName[13:29] + ".ts")
# Using os.rename to move the renamed file to the new location.
NewFileName = str(os.listdir("C:/VLC"))[2:39]
OldFileLocation = str(r"C:/VLC/")
NewFileLocation = str(r"C:/videotest/svansjon/")
time.sleep(3)
os.rename(OldFileLocation + NewFileName, NewFileLocation + NewFileName)
您可以在一行中完成。请注意,我使用的是 VLC 的控制台版本,我认为它是 Windows 上的 cvlc.exe
。该示例适用于 MPEG-TS
输入流:
cvlc <input> --play-and-exit --run-time 9000 \
--sout="#std{access=file,mux=ts,dst='/path/to/output.ts'}"
您可以制作一个脚本来配置输入、持续时间、目标路径和文件名并直接在那里记录。
我最近不得不学习我生疏的编码知识来尝试创建一个简单的脚本来记录我们舞台摄像机的纪录片流,这样,就不必有人整天呆在身边并制定繁琐的录制时间表,您可以 运行 在调度程序中显示名称可执行文件,流将被记录、重命名并传输到可公开访问的文件夹。
我在录制方面遇到了一些问题,主要是确保脚本 运行s 时没有任何问题。最理想的情况是,计算机不需要 .setFocus 等选项来向 VLC 发送命令,因为,如果有人在 VLC 即将发送录制命令时取消选择 VLC 怎么办?
我在这里花了大约一周的时间进行研究后编写了这段代码,它非常简单,但我非常感谢所有关于如何优化它的反馈。显然,在我们找到专门的 api 程序员将东西与我们的硬件集成之前,这更像是一个 alpha 阶段,但我一直喜欢自动化任务。
import time, SendKeys, os
# Start VLC using a udp stream playlist file
from pywinauto.application import Application
app = Application().Start(
cmd_line=u'"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" '
u'--started-from-file "C:\Program Files (x86)\VideoLAN\VLC\udp.xspf"')
qwidget = app.QWidget
qwidget.Wait('ready')
qwidget.SetFocus()
time.sleep(3)
# Record for 9000 seconds = 2h30m
SendKeys.SendKeys("+r")
time.sleep(9000)
# Quit VLC, leaving a non-corrupted .ts video file
app.Kill_()
# Ugly hack code for renaming the file. The folder is supposedly empty given that the code, if successful in
# creating a file here, must also be successful in moving the same file to the final directory.
# File is renamed with camera name, show name and date and time for the recording.
# The original naming format for VLC is something like
# vlc-record-2015-11-16-08h59m01s-udp___xxx.xxx.xxx.xxx_xxxx-.ts
# (Optimally I'd like to change the file output format to mp4 or similar, but couldn't figure out
# a way to use both Start from Playlist file and --sout options in the command line interface.
os.chdir(r"C:/VLC")
# Necessary?
FileName = str(os.listdir("C:/VLC"))[2:59]
ShowName = str("Swanlake")
os.rename(FileName, "Scenbild " + ShowName + " " + FileName[13:29] + ".ts")
# Using os.rename to move the renamed file to the new location.
NewFileName = str(os.listdir("C:/VLC"))[2:39]
OldFileLocation = str(r"C:/VLC/")
NewFileLocation = str(r"C:/videotest/svansjon/")
time.sleep(3)
os.rename(OldFileLocation + NewFileName, NewFileLocation + NewFileName)
您可以在一行中完成。请注意,我使用的是 VLC 的控制台版本,我认为它是 Windows 上的 cvlc.exe
。该示例适用于 MPEG-TS
输入流:
cvlc <input> --play-and-exit --run-time 9000 \
--sout="#std{access=file,mux=ts,dst='/path/to/output.ts'}"
您可以制作一个脚本来配置输入、持续时间、目标路径和文件名并直接在那里记录。