Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
512 views
in Technique[技术] by (71.8m points)

Python subprocess calling VLC command

I have the following command which works without issue in the Windows CLI:

"G:VLCvlc" --dshow-vdev="Video (00 Pro Capture HDMI 4K+)" --dshow-size=1920x1080 -V dummy --intf=dummy --dummy-quiet --video-filter=scene --no-audio --scene-path="C:<User>My location" --scene-format=jpeg --scene-prefix=test_file --scene-replace --run-time=1 --scene-ratio=24 "dshow://" vlc://quit

This takes a snapshot of whatever my capture card is displaying and saves this to file. When I try the same with Python as so:

import os
import subprocess

path = "C:\<User>\My location"
fname = "test_file"

os.chdir('G:\VLC')
process = subprocess.Popen(['vlc', ' --dshow-vdev="Video (00 Pro Capture HDMI 4K+)"', ' --dshow-size=1920x1080', ' -V dummy', ' --intf=dummy', 
                            ' --dummy-quiet', ' --video-filter=scene', 
                            ' --no-audio' ,path, ' --scene-format=jpeg', ' --scene-prefix=', fname, 
                            ' --scene-replace', ' --run-time=1', ' --scene-ratio=24', ' "dshow://"', ' vlc://quit'])

I get the following in the VLC log and no screenshot captured:

filesystem error: cannot open file G:VLC --dshow-vdev="Video (00 Pro Capture HDMI 4K+)" (Invalid argument)
dvdnav error: Could not open G:VLC --dshow-vdev="Video (00 Pro Capture HDMI 4K+)" with libdvdcss.
dvdnav error: Can't open G:VLC --dshow-vdev="Video (00 Pro Capture HDMI 4K+)" for reading
dvdnav error: vm: failed to open/read the DVD

Can anyone explain to me what the issue is?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

shlex can help you out, with this sort of thing.

The shlex class makes it easy to write lexical analyzers for simple syntaxes resembling that of the Unix shell. This will often be useful for writing minilanguages, (for example, in run control files for Python applications) or for parsing quoted strings.

import shlex
shlex.split(string) suggests something along the lines of:

['G:\VLC\vlc', '--dshow-vdev=Video (00 Pro Capture HDMI 4K+)', '--dshow-size=1920x1080', '-V', 'dummy', '--intf=dummy', '--dummy-quiet', '--video-filter=scene', '--no-audio', '--scene-path=C:\<User>\My location', '--scene-format=jpeg', '--scene-prefix=test_file', '--scene-replace', '--run-time=1', '--scene-ratio=24', 'dshow://', 'vlc://quit']


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...