我正在尝试通过带有大量参数的命令行运行VLC,因为我正在将捕获卡中的原始视频编码为传输流:
import os
import sys
import subprocess
comm_string = r'"G:\VLC\vlc" --ffmpeg-hw --avcodec-hw=any dshow:// :dshow-vdev="Video (00 Pro Capture HDMI 4K+)" :dshow-adev="Audio ' \
'(2- 00 Pro Capture HDMI 4K+)" :dshow-threads=8 :dshow-aspect-ratio=16\:9 :dshow-size="3840x2160" :dshow-pixel_format=yuv444p16le ' \
':dshow-tune=film :dshow-preset=lossless :dshow-profile=main10 show-vcodec=x265 :dshow-fps=50 :dshow-crf=0 :dshow-acodec=mp4a ' \
':dshow-stereo-mode=5 :dshow-force-surround-sound=0 :dshow-ab=128 :dshow-samplerate=44100 :no-dshow-config :live-caching=300 --sout ' \
'"#transcode{venc=ffmpeg,vcodec=mp2v,threads=8,aspect=16:9,width=3840,height=2160,fps=50,acodec=a52,ab=1500,channels=2,samplerate=48000,soverlay}' \
':standard{access=file,dst=-,mux=ts}"'
startupinfo = None
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
process = subprocess.Popen([comm_string], startupinfo=startupinfo)
...这将产生以下错误:
Traceback (most recent call last):
File "G:/HTPC Scripts/NPVR Command Line/Command Line.py", line 17, in <module>
process = subprocess.Popen([comm_string], startupinfo=startupinfo)
File "G:\Python36\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "G:\Python36\lib\subprocess.py", line 997, in _execute_child
startupinfo)
PermissionError: [WinError 5] Access is denied
...据我了解,您可以使用单个字符串将程序及其所有附带参数传递给子进程。不是吗?如果没有,应该如何修改语法?
谢谢
首先,为什么将r放在字符串的每一行中?它是一个字符串,所以一次使用就可以了。而且,您是否关心标准输出?如果您不在乎,我建议您使用os.popen()或os.system()