I had again a problem while coding my video editor… This is a function which will be executed when a button is clicked to import a video (the variables are in German language, don’t wonder and feel free to ask if you don’t understand something):
global Medien_Importierungen, Maximale_Breite, Maximale_Höhe, Tkinter_Bild
Videopfad = askopenfilename(filetypes =[('Video Files', '*.mp4')])
Geladenes_Video = cv2.VideoCapture(Videopfad)
Rückgabe, Einzelbild = Geladenes_Video.read()
if Einzelbild.shape[0] / Maximale_Höhe > Einzelbild.shape[1] / Maximale_Breite:
height = Maximale_Höhe
width = int(Einzelbild.shape[1] * height / Einzelbild.shape[0])
else:
width = Maximale_Breite
height = int(Einzelbild.shape[0] * width / Einzelbild.shape[1])
Einzelbild = cv2.resize(Einzelbild, (width, height))
Tkinter_Bild = ImageTk.PhotoImage(image=Image.fromarray(cv2.cvtColor(Einzelbild, cv2.COLOR_BGR2RGB)))
Thumbnail = Label(Medien, image = Tkinter_Bild)
if Medien_Importierungen % 2 == 0:
Thumbnail.place(x = Fenster.winfo_screenwidth() * 0.01 + Maximale_Breite / 2 - Einzelbild.shape[1] / 2, y = Fenster.winfo_screenheight() / 10 + (Fenster.winfo_screenwidth() * 0.01 + Maximale_Höhe) * int(Medien_Importierungen / 2) + Maximale_Höhe / 2 - Einzelbild.shape[0] / 2)
else:
Thumbnail.place(x = Fenster.winfo_screenwidth() * 0.11 + Maximale_Breite / 2 - Einzelbild.shape[1] / 2, y = Fenster.winfo_screenheight() / 10 + (Fenster.winfo_screenwidth() * 0.01 + Maximale_Höhe) * int(Medien_Importierungen / 2) + Maximale_Höhe / 2 - Einzelbild.shape[0] / 2)
Medien_Importierungen += 1
Now it shows every time I import a video the first time the first frame of the video, but when I execute the function a second time the picture from the first time will be white and only the first frame from the second video will be showed. That repeats everytime I import a video and I don’t know how remedy that problem…
I tried to create the whole label in the if-else-condition but that didn’t work either…
Please help, Alex
Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.