用于在VLC中录制UDP流的丑陋黑客。

时间:2015-11-16 08:19:20

标签: python stream udp vlc recording

我最近不得不拿起我非常生锈的编码知识来尝试创建一个简单的脚本来记录我们的舞台摄像机的记录流,这样就可以了,而不是有人不得不留下来并且整天创建繁琐的录制时间表,你可以只需在计划程序中运行show name executables,就会记录,重命名流并将其传输到可公开访问的文件夹。

我在录制过程中遇到了一些问题,主要是确保脚本运行时没有任何问题。最理想的是,计算机不需要诸如.setFocus之类的选项来向VLC发送命令,因为如果有人在发送记录命令时取消选择VLC会怎么样?

我在这里花了大约一周时间进行研究之后编写了这段代码并且非常简单,但我很欣赏所有关于如何优化的反馈。显然,这是一个alpha阶段阶段,直到我们有一个专门的api程序员将东西与我们的硬件集成,但我总是喜欢自动化任务。

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)

1 个答案:

答案 0 :(得分:0)

您可以在一行中完成。请注意,我使用的是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'}"

您可以创建一个脚本来配置输入,持续时间,目标路径和文件名,并直接在那里记录。