Встраивание окна ffplay в кадр tkinter с помощью функции SetParent win32 gui - PullRequest
0 голосов
/ 03 февраля 2020

Я использую, чтобы встроить окно 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 перестают отвечать без ошибок

, если кто-либо может помочь мне в этом я буду благодарен

1 Ответ

0 голосов
/ 03 февраля 2020

Root причина остановки ответа: 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.

...