Seite 1 von 1

pyinstaller und imageio

Verfasst: Mittwoch 24. März 2021, 15:55
von Streifenhase1
Hallo,

ich habe folgendes Problem, ich möchte ein Video mit imageio in einem tkinter fenster abspielen...

so weit so gut!

wenn ich meine .py datei mit pyinstall eine exe Datei mit "console" erstelle funktioniert das Programm!

wenn ich aber die .exe mit --noconsole erstelle funktioniert es nicht

jemand einen Tip!?

Hier ein Code der nicht von mir ist aber das selbe Problem wiederspeigelt

Code: Alles auswählen

import tkinter as tk, threading
import imageio
from PIL import Image, ImageTk

video_name = "test.mp4" #This is your video file path
video = imageio.get_reader(video_name)

def stream(label):
    
        
    for image in video.iter_data():
    frame_image = ImageTk.PhotoImage(Image.fromarray(image))
    label.config(image=frame_image)
    label.image = frame_image

  

if __name__ == "__main__":

    root = tk.Tk()
    my_label = tk.Label(root)
    my_label.pack()
    thread = threading.Thread(target=stream, args=(my_label,))
    thread.daemon = 1
    thread.start()
    root.mainloop()

 

Re: pyinstaller und imageio

Verfasst: Mittwoch 24. März 2021, 16:19
von Sirius3
Nein, das funktioniert nie sauber, weil man aus einem Thread heraus die GUI nicht ändern darf.
Sowas löst man mit after.
Die Einrückungen bei Deinem Code sind kaputt. Das my_ bei my_label ist überflüssig und kann weg. label ist ein sehr generischer Name. my_label ist zwar keine globale Variable, dafür aber video. Warum nur so halb richtig?

Re: pyinstaller und imageio

Verfasst: Mittwoch 24. März 2021, 17:30
von __blackjack__
Was Sirius3 schrob alles im Raspi-Forum schon mal erwähnt, inklusive fertigem Code der die Bilder per Queue in den GUI-Thread schaufelt: https://forum-raspberrypi.de/forum/thre ... n-tkinter/

Re: pyinstaller und imageio

Verfasst: Mittwoch 24. März 2021, 19:59
von Streifenhase1
abgesehen vom code (wie gesagt ist nicht meiner) denke ich das es noch ein Problem mit "pyinstaller" gibt der beim erstellen der ".exe" ohne console (pyinstaller -F ...py --noconsole)
das "ffmpeg" nicht richtig mit einbindet.

bei ausführen von "pyinstaller -F ....py --console" wird immerhin ein video abgespielt