在编译脚本中运行subprocess.popen具有很大的延迟

发布于 2025-01-26 17:55:40 字数 582 浏览 3 评论 0原文

编辑:在此特定示例中,在Windows 10上使用Python 3.8。

我需要通过subprocess.popen运行ffprobe,以便我可以捕获和解析输出。如果我在脚本中执行此操作,它几乎可以立即运行,但是如果我用Pyinstaller编译脚本并做同样的事情,则需要超过0.8秒的时间才能完成。是否可以从编译脚本中更快地执行该技巧或任何方法?如果存在,我愿意听到特定于FFProbe的答案。

这就是我目前正在使用的。额外的代码是为了确保FFProbe在运行时不会闪烁控制台窗口(卸下控制台窗口实际上使其平均更快0.1秒)。

startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
p = subprocess.Popen(f'ffprobe -show_format -show_streams -of json "{file}"', startupinfo=startupinfo, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()

Edit: In this specific example, Python 3.8 is being used on Windows 10.

I need to run FFprobe through subprocess.Popen so I can capture and parse the output. If I do this in a script, it runs almost instantly, but if I compile my script with PyInstaller and do the same thing, it takes over 0.8 seconds to complete. Is there a trick or any way I can execute it faster from the compiled script? I'm willing to hear FFprobe-specific answers if they exist.

This is what I'm using currently. The extra code is for ensuring FFprobe doesn't flash a console window while running (removing the console window actually made it 0.1 seconds faster on average).

startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
p = subprocess.Popen(f'ffprobe -show_format -show_streams -of json "{file}"', startupinfo=startupinfo, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文