python-3.x - Python3 子进程“拒绝访问”
问题描述
我正在尝试通过带有大量参数的命令行运行 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
...我的理解是,您可以使用单个字符串将程序及其所有伴随参数传递到子进程中。不是这样吗?如果没有,我应该如何修改我的语法?
谢谢
解决方案
这是解决方案顺便说一句:
import os
import sys
import subprocess
os.chdir('G:\\VLC\\')
startupinfo = None
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
process = subprocess.Popen([
'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}"',
], stdout=subprocess.PIPE, startupinfo=startupinfo)
推荐阅读
- html - HTML/CSS Button Hover 将其他所有内容移开?
- c# - 从下拉列表中检索值到控制器
- javascript - 在同一浏览器选项卡中连接两个 RTCPeerConnections 时,WebRTC 连接偶尔会失败
- arrays - MongoDB返回其中数组包含查询数组中的至少一项
- html - 如何在窗口滚动上显示进度边框
- javascript - 正常运行 6 小时后 Redis 使用 100% CPU
- python - Python数据科学初学者函数题
- postgresql - 如何返回由触发器为 JOOQ 记录存储创建的值?
- r - If, Else 语句错误
- python - 如何将我的后端烧瓶微服务与我的前端烧瓶代码连接起来?