Python Forum
[WxPython] Problems with making a Video Player in WxPython
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[WxPython] Problems with making a Video Player in WxPython
#1
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
I'm just an osu!addict and degenerate who happens to like programming.
Reply
#2
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=
Reply
#3
I am lately enthralled with pygame for audio/visual solutions. Suggest investigating that and playing around. Very powerful.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] Embedding a Video in Video Player WhatsupSmiley 0 3,276 Jan-28-2019, 06:24 PM
Last Post: WhatsupSmiley
  video player inside a frame/panel in python raspberry pi desktop application MATHEWS 1 1,392 Dec-12-2018, 11:42 AM
Last Post: Larz60+
  Problems using Wxpython Carles 1 2,006 Nov-28-2018, 03:09 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020