2 #Copyright 2009 - 2010 Paul Hänsch
4 #This file is part of Viper.
6 #Viper is free software: you can redistribute it and/or modify
7 #it under the terms of the GNU General Public License as published by
8 #the Free Software Foundation, either version 3 of the License, or
9 #(at your option) any later version.
11 #Viper is distributed in the hope that it will be useful,
12 #but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 #GNU General Public License for more details.
16 #You should have received a copy of the GNU General Public License
17 #along with Viper. If not, see <http://www.gnu.org/licenses/>
23 This class provides basic video playback and filter capability.
25 The class is meant to be inheritet by higher level video widgets.
27 slave (int) - pid of the enslaved mplayer
28 filters (list of - a list of filters, you should use add_filter() and
29 strings) del_filter() to access it
30 width (int) - the inheriting class must set the video width
31 height (int) - the inheriting class must set the video height
42 Stop playback of the video
44 if self.slave != None:
46 os.kill(self.slave, 15)
48 print 'video slave has been terminated unexpectedly'
51 def play(self, wid = None, width = None, height = None):
53 Start playback of the video
55 The video will be looped until stop() is called or hell freezes over
56 wid - X11 window id of a window which shall serve as video frame
57 if 'wid' is omitted the play() will open a new window
61 width = int(self.width)
63 height = int(self.height)
67 args = ['', '-really-quiet', '-fixed-vo', '-loop', '0',
68 '-nosound', '-framedrop', '-slave', '-vo', 'x11',
69 '-x', str(width), '-y', str(height)]
70 args.extend(self.slave_subcommand())
72 args = ['', '-wid', str(wid), '-really-quiet', '-fixed-vo',
73 '-loop', '0', '-nosound', '-framedrop', '-slave',
74 '-x', str(width), '-y', str(height), '-vo', 'x11']
75 args.extend(self.slave_subcommand())
77 self.slave = os.spawnvp(os.P_NOWAIT, 'mplayer', args)
79 def slave_subcommand(self):
81 Return a list of mplayer command line arguments to play the chunk
83 The argument list will have the form
84 ['videofile', '-ss', start, '-frames', frames, filters... ]
85 the list can easily be appended to a mplayer command line
87 ret = [self.slave_video()[0]]
88 for filter in self.filters:
90 if self.slave_video().__len__() > 1:
91 ret.extend(self.slave_video()[1:])
95 def slave_video(self):
97 Return a list of mplayer command line arguments,
98 which specifies the video to play.
100 This can be a filename or an URL. The method is meant
101 to be overridden as it only returns an empty string.
105 def add_filter(self, filterdef):
107 Apply a videofilter to the chunk.
109 Filterdef is a list of mplayer options,
110 i.e. ['-vf-add', 'expand=-60:0'].
111 Several filters can be applied to one chunk.
114 self.filters.append(filterdef)
117 def del_filter(self, filterdef):
119 Opposite to add_filter.
121 Removes a given filter from the list
124 self.filters.remove(filterdef)
127 def filter_eq(self, f1, f2):
129 Check if two filter lines are equal
131 if str(f1) == str(f2): return True