Python Forum

Full Version: Problems with making a Video Player in WxPython
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was trying to make a Video Player in WxPython, my overall goal being a video editor. The problem I'm having here is that the video plays too slowly, and as a result, the audio gets out of sync. Another thing to point out is that sometimes the video will just blink a white frame. The way I made it to work goes as follows: A function makes threads of the video and audio functions and starts them. The video and audio functions use threading events to make sure they start their actions at the same time. I put the code for the video function below, if you need any other info I'll supply it as soon as I can. Thanks in advance for any help with this.

    def play_video(self):
        frame = self.clip.get_frame(0)  # self.clip is a MoviePy object, this function gets the frame from a specified timestamp
        self.display_frame(frame)  # Code for this is below
        self.videoEvent.set()  # This is the video event
        self.audioEvent.wait()  # Wait for the audio event (which is set from the audio function)
        for t in np.arange(1.0 / self.fps, self.clip.duration - .001, 1.0 / self.fps):  # self.fps is 15
            frame = self.clip.get_frame(t)
            self.display_frame(frame)
            if self.playing is False and not self.videoEvent.is_set():  # This if statement follows through when the window closes and these values are set to be so (except the window freezes up but that's a separate problem)
                self.videoEvent.set()
                return
    def display_frame(self, frame):
        img = wx.Image(self.clip.w, self.clip.h)
        img.SetData(frame)
        self.videoScreen.SetBitmap(wx.Bitmap(img))  # self.videoScreen is a wx.Image defined during __init__, it's just a plain black screen
        self.wxClass.panel.Refresh()  # self.wxClass is the instance of the wx class which manages everything
there are packages you can use. One is: https://pypi.org/project/vidpy/
others can be found: https://pypi.org/search/?q=%27video+editor%27&o=
I am lately enthralled with pygame for audio/visual solutions. Suggest investigating that and playing around. Very powerful.