PaulleDemon / tkVideoPlayer

Video player for tkinter.
MIT License
79 stars 25 forks source link

No sound in videos? #2

Open victorccaldas opened 2 years ago

PaulleDemon commented 2 years ago

@victorccaldas Hello, Sorry but unfortunately I couldn't find a good library to play sound. So I decided not to include it, Maybe in the future, we can try that. Thank you.

maru0123-2004 commented 2 years ago

In my library(Marusoftware/tkmedia3), using sounddevice library for that. And also, I was tried load in real time, but it cause seek bug(for example, segfault, hung up, and so...). In your library, you load all frames on memory. But it is only video. When load both video and audio full frames on memory, it may be make high memory usage...

I think your library is very similar to mine. If you are ok, I want to work for that together.. (I'm sorry for my bad English)

PaulleDemon commented 2 years ago

Hello @maru0123-2004, hope you are doing well. In the beginning, I was also trying to create an audio playback along with the video. But, I quickly realized the complexity involved in syncing audio and the video. I am happy to hear that you are working on a solution for that. Currently, my library loads all the frames into memory, I was working on a simple solution of poping the initial frames if the memory exceeds a certain memory limit set by the user. But, unfortunately, I was struck with a major project that requires my attention and time, hence couldn't work on it. I would probably in the future rework it.

I would also love to help and contribute during my free time to your library as long as it is open-sourced under MIT or any other permissive free software license.

The logic to seek, pause and play audio would be the same, take a look at this answer (it could provide an insight on how you could make it work): https://stackoverflow.com/a/69041999/15993687 .

If you ever need any help you can tag me under this issue, I'll look into it when I am free. Thank you have a nice day.

Update: We no longer load frames into memory to allow the playing of large files easily.

blankschyn commented 1 year ago

I had a hard time using tkVideoPlayer, especially when it comes to playing sounds (which is pretty crucial for a video player).

So in the end I used vlc-python in a Label like this, and all the struggle was gone:

class VideoPlayer(tk.Label):
    def __init__(self, app, frame: tk.LabelFrame):
        super().__init__()
        self.master = frame
        # Create a basic vlc instance
        self.instance = vlc.Instance()
        self.media = None
        # Create an empty vlc media player
        self.mediaplayer = self.instance.media_player_new()

    def open_file(self):
        """Open a media file in a MediaPlayer
        """
        file_name = filedialog.askopenfilename(title="Please choose a video file.")
        if file_name:
            self.media = self.instance.media_new(file_name)
            self.mediaplayer.set_media(self.media)

            # The media player has to be 'connected' to the Frame (otherwise the
            # video would be displayed in it's own window). This is platform
            # specific, so we must give the ID of the Frame (or similar object) to
            # vlc. Different platforms have different functions for this
            if platform.system() == "Linux":  # for Linux using the X Server
                self.mediaplayer.set_xwindow(int(self.master.winfo_id()))
            elif platform.system() == "Windows":  # for Windows
                self.mediaplayer.set_hwnd(int(self.master.winfo_id()))
            elif platform.system() == "Darwin":  # for MacOS
                self.mediaplayer.set_nsobject(int(self.master.winfo_id()))

            self.media.parse()
            self.mediaplayer.play()
cool-dev-guy commented 9 months ago

@victorccaldas I made an implementation of a tkinter video player where you can also play AUDIO and VIDEO simultaneously.github page

pip install tkintervideo
from tkintervideo import player
from tkintervideo.tools import Controls
import tkinter as tk
from tkinter import ttk
import sv_ttk
import time

class App(tk.Tk):
    def __init__(self,*args,**kwargs):
        super().__init__(*args,**kwargs)
        sv_ttk.set_theme('dark')
        self.m_widget = player.Player(self,height=200,width=300)

        self.rowconfigure(0,weight=1)
        self.rowconfigure(1,weight=0)
        self.columnconfigure(0,weight=1)

        self.m_widget.grid(column=0,row=0,sticky=tk.NSEW,padx=5,pady=5)
        self.m_widget.load('output.avi')

        self.controls = Controls(self,self.m_widget)
        self.m_widget.bind("<<Duration>>",self.controls.update_scale)
        self.controls.grid(column=0,row=1,sticky=tk.NSEW,padx=10,pady=10)
myApp = App()
myApp.mainloop()

Also if you liked this project,star it :)

WizardEel commented 7 months ago

Did you end up figuring out how to implement sound into tkvideoplayer? or should i use something else

PaulleDemon commented 7 months ago

@WizardEel https://stackoverflow.com/questions/69039745/python-tkinter-audio-playback-gui-play-pause-functionality-with-pyaudio-cant/69041999#69041999

Try using this to integrate sound, If you are unable to do so let me know.