小编Eli*_*hen的帖子

在 python 窗口(Tkinter)应用程序中抑制子进程控制台输出

我正在尝试在使用的 python 应用程序可执行文件中运行以下代码

pyinstaller -w -F 脚本.py

def ffmpeg_command(sec):
    cmd1 = ['ffmpeg', '-f','gdigrab','-framerate',config.get('FFMPEG_Settings','Framerate'),'-i','desktop',gen_filename_from_timestamp_and_extension()]


    proc = subprocess.Popen(cmd1,stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

    duration = sec
    sleeptime = 0
    while proc.poll() is None and sleeptime < duration: 
        # Wait for the specific duration or for the process to finish
        time.sleep(1)
        sleeptime += 1

    proc.terminate()
Run Code Online (Sandbox Code Playgroud)

当按下 Tkinter 按钮时运行上面的代码,并且从按钮单击处理程序调用此代码。

我的问题是,当我运行 exe 时,它​​不会运行 ffmpeg。但是,如果我将命令设置为:

proc = subprocess.Popen(cmd1)
Run Code Online (Sandbox Code Playgroud)

FFMPEG 确实运行了,我得到了我想要的电影文件,但我可以看到 FFMPEG 的控制台窗口。所以我最终在我的电影中获得了控制台窗口。(我负责最小化按钮单击处理程序中的 Tkinter 窗口)

我的问题是如何抑制控制台窗口并仍然让 FFMPEG 以我想要的方式运行?我看着下面的线程,但不能使它工作: 如何子的隐藏输出在Python 2.7打开一个程序与Python最小化或隐藏

谢谢

python subprocess ffmpeg pyinstaller windows-console

3
推荐指数
1
解决办法
1383
查看次数