我最近的工作涉及以编程方式制作视频.在python中,典型的工作流程看起来像这样:
import subprocess, Image, ImageDraw
for i in range(frames_per_second * video_duration_seconds):
img = createFrame(i)
img.save("%07d.png" % i)
subprocess.call(["ffmpeg","-y","-r",str(frames_per_second),"-i", "%07d.png","-vcodec","mpeg4", "-qscale","5", "-r", str(frames_per_second), "video.avi"])
Run Code Online (Sandbox Code Playgroud)
此工作流程为视频中的每个帧创建一个图像并将其保存到磁盘.保存所有图像后,调用ffmpeg以构建来自所有图像的视频.
将图像保存到磁盘(而不是在内存中创建图像)会占用此处的大部分周期,并且似乎不需要.有没有办法执行相同的功能,但没有将图像保存到磁盘?因此,将调用ffmpeg并构建图像并在构造后立即将其提供给ffmpeg.
我有一个带有GUI的程序,通过Popen调用运行外部程序:
p = subprocess.Popen("<commands>" , stdout=subprocess.PIPE , stderr=subprocess.PIPE , cwd=os.getcwd())
p.communicate()
Run Code Online (Sandbox Code Playgroud)
但是无论我做什么,都会弹出控制台(我也尝试将NUL传递给文件句柄).如果没有得到我调用的二进制文件来释放它的控制台,有没有办法做到这一点?
我正在将项目移植到Python3,我在Windows上遇到意外错误:
基本上在Windows上的Python 3.6上,每次使用子进程创建进程时,我都有以下异常:
d:\temp\backpack\venv\myvenv_py3.6\lib\site-packages\git\cmd.py:1011: in _call_process
return self.execute(call, **exec_kwargs)
d:\temp\backpack\venv\myvenv_py3.6\lib\site-packages\git\cmd.py:732: in execute
**subprocess_kwargs
D:\temp\cpython-3.6.3\Lib\subprocess.py:611: in __init__
_cleanup()
D:\temp\cpython-3.6.3\Lib\subprocess.py:220: in _cleanup
res = inst._internal_poll(_deadstate=sys.maxsize)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <subprocess.Popen object at 0x0000000004FD53C8>
_deadstate = 9223372036854775807
_WaitForSingleObject = <built-in function WaitForSingleObject>
_WAIT_OBJECT_0 = 0, …Run Code Online (Sandbox Code Playgroud) 我通过多处理实现运行我的函数
def assign_task(self, module, command):
logging.debug("Assigning task for {0}".format(command._get_module_id()))
if self.queue is None:
self.queue = JoinableQueue()
if self.processes is None:
self.processes = [Process(target=self.do_execute) for i in range(self.max_process)]
for process in self.processes:
process.daemon = True
process.start()
logging.debug("Queuing message {0}".format(command._get_module_id()))
self.queue.put((module, command))
def do_execute(self):
# the code
Run Code Online (Sandbox Code Playgroud)
但出现这个错误
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\muhammad.aqshol\AppData\Local\Programs\Python\Python38\lib\multiprocessing\spawn.py", line 107, in spawn_main
new_handle = reduction.duplicate(pipe_handle,
File "C:\Users\muhammad.aqshol\AppData\Local\Programs\Python\Python38\lib\multiprocessing\reduction.py", line 79, in duplicate
return _winapi.DuplicateHandle(
OSError: [WinError 6] The handle is …Run Code Online (Sandbox Code Playgroud) 我有一个 Electron 应用程序xxx.exe,它生成一个从 PyInstaller 创建的可执行文件yyy.exe。在 , 中yyy.exe,我终于尝试git通过subprocess.check_output(). 可悲的是,调用check_output()throws [WinError 6] The handle is invalid。
如果yyy.exe直接在命令行上启动,一切运行正常。该问题仅发生在 Windows 上。我的假设是有一些检查stdin会触发异常,因为通过 Electron 应用程序运行不提供任何标准输入。
任何提示将不胜感激!提前致谢!
python ×5
console ×1
electron ×1
ffmpeg ×1
image ×1
popen ×1
pyinstaller ×1
python-3.x ×1
pythonw ×1
stream ×1
subprocess ×1