use mpv for gif

This commit is contained in:
grimhilt 2023-08-30 10:32:56 +02:00
parent f723d883fb
commit 958fb9378a

View File

@ -51,11 +51,9 @@ class MediaFactory:
print(self.file) print(self.file)
self.supported = True self.supported = True
match file['type']: match file['type']:
case "image/gif":
self.gif_player()
case "image/jpeg" | "image/jpg": case "image/jpeg" | "image/jpg":
self.image_player() self.image_player()
case "video/mp4": case "video/mp4" | "image/gif":
self.video_player() self.video_player()
case _: case _:
print(file['type'], " not supported") print(file['type'], " not supported")
@ -75,10 +73,6 @@ class MediaFactory:
video_player = VideoPlayer(self.parent, self.file) video_player = VideoPlayer(self.parent, self.file)
self.time = video_player.time self.time = video_player.time
def gif_player(self):
gif_player = GIFPlayer(self.parent, self.file)
self.time = gif_player.time
class VideoPlayer: class VideoPlayer:
def __init__(self, parent, file): def __init__(self, parent, file):
self.file = file self.file = file
@ -93,36 +87,3 @@ class VideoPlayer:
self.time = int(self.total_frames * ((int(1000/self.fps)))) self.time = int(self.total_frames * ((int(1000/self.fps))))
self.mpv_instance.play(self.path) self.mpv_instance.play(self.path)
class GIFPlayer():
def __init__(self, parent, file):
self.parent = parent
self.file = file
self.path = './data/' + self.file['name']
self.current_frame = 0
self.time = 0
self.play_gif()
def load_gif_frames(self):
gif = Image.open(self.path)
frames = []
try:
while True:
frames.append(ImageTk.PhotoImage(gif.copy()))
gif.seek(len(frames)) # Move to the next frame
except EOFError:
pass # Reached the end of the GIF
return frames
def play_gif(self):
try:
frame = ImageTk.PhotoImage(file=self.path, format="gif -index %i" %(self.current_frame))
self.parent.label.config(image=frame)
self.parent.label.image = frame
self.current_frame = self.current_frame + 1
self.after((100), self.play_gif)
except:
pass