Multiprocess videoplayer
I have coded a program with python and vlc that plays some videos, but whenever I try to play 3 videos at once, Windows closes the program, I'm guessing that the reason is that one process can't play 3 videos at once (but I don't really know). My trimmed program plays one video (trhough a global variable, os it's easy to change) and once you press the number 2 on the keyboard it put the data from a video on the queue to be played by another process. The new process starts and makes some prints, then it should start the new video and another one, so we should have two videos playing, one on the left part of the screen and the other on the right. I've done this on linear programming, but I can't make the new process to start the videos. I oame from a C/C++ background so I don't know if it's something I didn't fully grasp about the multiprocess on Python or something else that I'm doing wrong. Its huge for a miniexample (300 lines), but I didn't know how to make it shorter: # import external libraries import wx # 2.8 import vlc import pdb # import standard libraries import user import urllib import multiprocessing VIDEO1 = "Insert_your_first_video.mp4" VIDEO2 = "Insert_your_second_video.mp4" class MyOpener(urllib.FancyURLopener): version = "App/1.7" # doesn't work version = "Mozilla/4.0 (MSIE 6.0; Windows NT 5.0)2011-03-10 15:38:34" # works class Consumer(multiprocessing.Process): def __init__(self, task_queue): multiprocessing.Process.__init__(self) self.task_queue = task_queue def run(self): app = wx.App() proc_name = self.name print "waiting for queue" while True: # While queue not empy print self.task_queue.qsize() next_task = self.task_queue.get() global dual, midsection dual = True midsection = next_task.d player2 = Player("Dual PyVLC Player") player2.Centre() # show the player window centred and run the application print "parametro a " + str(next_task.a) print "parametro b " + str(next_task.b) print "parametro c " + str(next_task.c) print "parametro d " + str(next_task.d) # tasks.put(Task(media, dual, time, midsection)) player2.playFile(next_task.a,next_task.c,True) player2.playFile(VIDEO2,next_task.c,True) #player.vidplayer1.set_media(next_task.a) #player.vidplayer2.play() player2.Maximize(True) player2.OnFullscreen(None) player2.SetTransparent(255) player2.SetFocus() player2.Show() #player2.vidplayer1.set_title(next_task.a) '''player1.SetTransparent(0) player1.timer1.Start(fadetime) player1.set_amount(0)''' def playFile(self,moviefile,time,principal): # Creation self.Media = self.Instance.media_new_path(moviefile) self.SetTitle("Monkey") #self.SetIcon(wx.Icon('Monkey.ico', wx.BITMAP_TYPE_ICO)) if dual: if principal: #If we dont set any handle it starts in another window, maybe usefull for dual screens? self.vidplayer1.set_media(self.Media) #self.vlchandle = self.vidplayer1.get_xwindow() self.vidplayer1.set_hwnd(self.videopanel.GetHandle()) self.OnPlay(None,True) self.vidplayer1.set_time(time) else: self.vidplayer2.set_media(self.Media) #self.vlchandle = self.vidplayer2.get_xwindow() self.vidplayer2.set_hwnd(self.videopanel2.GetHandle()) self.OnPlay(None,False) self.vidplayer2.set_time(time) else: self.vidplayer1.set_media(self.Media) #self.vlchandle = self.vidplayer1.get_xwindow() self.vidplayer1.set_hwnd(self.videopanel.GetHandle()) self.OnPlay(None,True) self.vidplayer1.set_time(time) class Task(object): def __init__(self, a, b, c, d): self.a = a # can't be media, it's not pickable self.b = b # boolean self.c = c # Number (time) self.d = d # boolean def __str__(self): return '%s * %s' % (self.a, self.b, self.c, self.d) class Player(wx.Frame): """The main window has to deal with events. """ def __init__(self, title, OS="windows"): self.OS = OS wx.Frame.__init__(self, None, -1, title, pos=wx.DefaultPosition, size=(950, 500)) self.SetBackgroundColour(wx.BLACK) # Panels # The first panel holds the video/videos and it's all black self.videopanel = wx.Panel(self, -1) self.videopanel.SetBackgroundStyle(wx.BG_STYLE_COLOUR) self.videopanel.SetBackgroundColour(wx.BLACK) if dual: videopanel2 = wx.Panel(self, -1)
multiprocessing videoplayer
I have coded a program with python and vlc that plays some videos, but whenever I try to play 3 videos at once, Windows closes the program, I'm guessing that the reason is that one process can't play 3 videos at once (but I don't really know). My trimmed program plays one video (trhough a global variable, os it's easy to change) and once you press the number 2 on the keyboard it put the data from a video on the queue to be played by another process. The new process starts and makes some prints, then it should start the new video and another one, so we should have two videos playing, one on the left part of the screen and the other on the right. I've done this on linear programming, but I can't make the new process to start the videos. I oame from a C/C++ background so I don't know if it's something I didn't fully grasp about the multiprocess on Python or something else that I'm doing wrong. Its huge for a miniexample (300 lines), but I didn't know how to make it shorter: # import external libraries import wx # 2.8 import vlc import pdb # import standard libraries import user import urllib import multiprocessing VIDEO1 = "Insert_your_first_video.mp4" VIDEO2 = "Insert_your_second_video.mp4" class MyOpener(urllib.FancyURLopener): version = "App/1.7" # doesn't work version = "Mozilla/4.0 (MSIE 6.0; Windows NT 5.0)2011-03-10 15:38:34" # works class Consumer(multiprocessing.Process): def __init__(self, task_queue): multiprocessing.Process.__init__(self) self.task_queue = task_queue def run(self): app = wx.App() proc_name = self.name print "waiting for queue" while True: # While queue not empy print self.task_queue.qsize() next_task = self.task_queue.get() global dual, midsection dual = True midsection = next_task.d player2 = Player("Dual PyVLC Player") player2.Centre() # show the player window centred and run the application print "parametro a " + str(next_task.a) print "parametro b " + str(next_task.b) print "parametro c " + str(next_task.c) print "parametro d " + str(next_task.d) # tasks.put(Task(media, dual, time, midsection)) player2.playFile(next_task.a,next_task.c,True) player2.playFile(VIDEO2,next_task.c,False) #player.vidplayer1.set_media(next_task.a) #player.vidplayer2.play() player2.Maximize(True) player2.OnFullscreen(None) player2.SetTransparent(255) player2.SetFocus() player2.Show() #player2.vidplayer1.set_title(next_task.a) '''player1.SetTransparent(0) player1.timer1.Start(fadetime) player1.set_amount(0)''' def playFile(self,moviefile,time,principal): # Creation self.Media = self.Instance.media_new_path(moviefile) self.SetTitle("Monkey") #self.SetIcon(wx.Icon('Monkey.ico', wx.BITMAP_TYPE_ICO)) if dual: if principal: #If we dont set any handle it starts in another window, maybe usefull for dual screens? self.vidplayer1.set_media(self.Media) #self.vlchandle = self.vidplayer1.get_xwindow() self.vidplayer1.set_hwnd(self.videopanel.GetHandle()) self.OnPlay(None,True) self.vidplayer1.set_time(time) else: self.vidplayer2.set_media(self.Media) #self.vlchandle = self.vidplayer2.get_xwindow() self.vidplayer2.set_hwnd(self.videopanel2.GetHandle()) self.OnPlay(None,False) self.vidplayer2.set_time(time) else: self.vidplayer1.set_media(self.Media) #self.vlchandle = self.vidplayer1.get_xwindow() self.vidplayer1.set_hwnd(self.videopanel.GetHandle()) self.OnPlay(None,True) self.vidplayer1.set_time(time) class Task(object): def __init__(self, a, b, c, d): self.a = a # can't be media, it's not pickable self.b = b # boolean self.c = c # Number (time) self.d = d # boolean def __str__(self): return '%s * %s' % (self.a, self.b, self.c, self.d) class Player(wx.Frame): """The main window has to deal with events. """ def __init__(self, title, OS="windows"): self.OS = OS wx.Frame.__init__(self, None, -1, title, pos=wx.DefaultPosition, size=(950, 500)) self.SetBackgroundColour(wx.BLACK) # Panels # The first panel holds the video/videos and it's all black self.videopanel = wx.Panel(self, -1) self.videopanel.SetBackgroundStyle(wx.BG_STYLE_COLOUR) self.videopanel.SetBackgroundColour(wx.BLACK) if dual: videopanel2 = wx.Panel(self, -1)
Non working Parallel videoplayer
I have coded a program with python and vlc that plays some videos, but whenever I try to play 3 videos at once, Windows closes the program, I'm guessing that the reason is that one process can't play 3 videos at once (but I don't really know). My trimmed program plays one video (trhough a global variable, os it's easy to change) and once you press the number 2 on the keyboard it put the data from a video on the queue to be played by another process. The new process starts and makes some prints, then it should start the new video and another one, so we should have two videos playing, one on the left part of the screen and the other on the right. I've done this on linear programming, but I can't make the new process to start the videos. I oame from a C/C++ background so I don't know if it's something I didn't fully grasp about the multiprocess on Python or something else that I'm doing wrong. Here is the linear working version (commented lines 206-220) and the parallel non-working version lines (221-225) Comment/Uncomment to toogle bewtween them. Its huge for a miniexample (383 lines), but I didn't know how to make it shorter (it comes from a 3000+ project): # import external libraries import wx # 2.8 import vlc import pdb from time import sleep # import standard libraries import user import urllib VIDEO1 = "Insert_your_first_video.mp4" VIDEO2 = "Insert_your_second_video.mp4" class MyOpener(urllib.FancyURLopener): version = "App/1.7" # doesn't work version = "Mozilla/4.0 (MSIE 6.0; Windows NT 5.0)2011-03-10 15:38:34" # works class Consumer(multiprocessing.Process): def __init__(self, task_queue): multiprocessing.Process.__init__(self) self.task_queue = task_queue def run(self): app = wx.App() proc_name = self.name print "waiting for queue" while True: # While queue not empy print self.task_queue.qsize() next_task = self.task_queue.get() global dual, midsection midsection = next_task.d dual = True player2 = Player("Dual PyVLC Player") player2.Centre() # show the player window centred and run the application print "parametro a " + str(next_task.a) print "parametro b " + str(next_task.b) print "parametro c " + str(next_task.c) print "parametro d " + str(next_task.d) # tasks.put(Task(media, dual, time, midsection)) player2.playFile(VIDEO1,next_task.c,True) player2.playFile(VIDEO2,next_task.c,False) #player.vidplayer1.set_media(next_task.a) #player.vidplayer2.play() player2.Maximize(True) player2.OnFullscreen(None) player2.SetTransparent(255) player2.SetFocus() player2.Show(True) #sleep(1) #player2.vidplayer1.set_title(next_task.a) '''player1.SetTransparent(0) player1.timer1.Start(fadetime) player1.set_amount(0)''' def playFile(self,moviefile,time,principal): # Creation self.Media = self.Instance.media_new_path(moviefile) self.SetTitle("Monkey") #self.SetIcon(wx.Icon('Monkey.ico', wx.BITMAP_TYPE_ICO)) if dual: if principal: #If we dont set any handle it starts in another window, maybe usefull for dual screens? self.vidplayer1.set_media(self.Media) #self.vlchandle = self.vidplayer1.get_xwindow() self.vidplayer1.set_hwnd(self.videopanel.GetHandle()) self.OnPlay(None,True) self.vidplayer1.set_time(time) else: self.vidplayer2.set_media(self.Media) #self.vlchandle = self.vidplayer2.get_xwindow() self.vidplayer2.set_hwnd(self.videopanel2.GetHandle()) self.OnPlay(None,False) self.vidplayer2.set_time(time) else: self.vidplayer1.set_media(self.Media) #self.vlchandle = self.vidplayer1.get_xwindow() self.vidplayer1.set_hwnd(self.videopanel.GetHandle()) self.OnPlay(None,True) self.vidplayer1.set_time(time) class Task(object): def __init__(self, a, b, c, d): self.a = a # can't be media, it's not pickable self.b = b # boolean self.c = c # Number (time) self.d = d # boolean def __str__(self): return '%s * %s' % (self.a, self.b, self.c, self.d) class Player(wx.Frame): """The main window has to deal with events. """ def __init__(self, title, OS="windows"): self.OS = OS wx.Frame.__init__(self, None, -1, title, pos=wx.DefaultPosition, size=(950, 500)) self.SetBackgroundColour(wx.BLACK) # Panels # The first panel holds the video/videos and it's all black self.videop
Re: Non working Parallel videoplayer
I think it has to be with some functions that I think they are defined on the "forked" processes and maybe they don't, if I create a class on the new process it should have all the defined functions than the original right? -- https://mail.python.org/mailman/listinfo/python-list