gpt4 book ai didi

python - 使用 SetParent win32gui 函数将 ffplay 窗口嵌入到 tkinter 框架中

转载 作者:行者123 更新时间:2023-12-04 23:23:21 25 4
gpt4 key购买 nike

我用来将 ffplay 窗口嵌入到我的 tkinter 框架中。

那是我的代码:

file = "path/to/the/file.mp4"
command = subprocess.Popen(["ffplay","-i","%s"%file],stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True,)
pid = gw.getWindowsWithTitle('%s'%file) #getting the hwnd of the ffplay window
hwnd = re.findall(r'\d+',str(pid))
x = int(videoWidget.winfo_x()) #video widget is the target tkinter frame
y =int(videoWidget.winfo_y())
width = int(videoWidget.winfo_width())
height = int(videoWidget.winfo_height())
win32gui.MoveWindow(int(hwnd[-1]), int(x), int(y),int(width) , int(height), 1) # trying to move the ffplay window to the videowidget geometry
win32gui.SetParent(int(hwnd[-1]),int(stream_id)) #trying to set the parent of the ffplay window to the videowidget, that should show the ffplay window in the tkinter frame

代码运行没有任何错误,但是 ffplay 窗口和 tkinter 窗口都停止响应而没有任何错误

如果有人可以帮助我,我将不胜感激

最佳答案

停止响应的根本原因:stdout=PIPE和/或 stderr=PIPE .
它阻止 ffmpeg 的输出并造成僵局。

您可以为 ffmpeg 的输出创建一个新控制台。 .

我的测试样本:

import subprocess
from subprocess import Popen, CREATE_NEW_CONSOLE
import pygetwindow as gw
import win32gui
import regex as re
import time
file = "path/to/the/file.mp4"
proc = subprocess.Popen(["ffplay","-i","%s"%file], creationflags = CREATE_NEW_CONSOLE)

time.sleep(2) #make sure the window has been started and available to find.
pid = gw.getWindowsWithTitle('%s'%file) #getting the hwnd of the ffplay window
hwnd = re.findall(r'\d+',str(pid))
print(hwnd)
x = 0 #video widget is the target tkinter frame
y = 0
width = 800
height = 500
win32gui.MoveWindow(int(hwnd[-1]), int(x), int(y),int(width) , int(height), 1) # trying to move the ffplay window to the videowidget geometry

此外,在调用 getWindowsWithTitle 之前,应确保已启动窗口。 .

关于python - 使用 SetParent win32gui 函数将 ffplay 窗口嵌入到 tkinter 框架中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60032301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com