2 #Copyright 2009 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 object contains a single piece of viedeo from one file.
25 The video can be the whole video stored in the file (which is the
26 default) or a part of this video. The file is never affected due to
27 operations on this object and temporary files are not created.
29 Interesting object properties:
30 videoprops - a dictionary containing video properties as reported from mplayer
31 keys are for example ID_VIDEO_WIDTH or ID_LENGTH
32 run 'mplayer -identify videofile' to get an idea of the values
36 def __init__(self, file, start = None, frames = None):
40 file (string) - the name of a video file
41 start (float) - the second which marks the start of the chunk
42 in video compression formats which are based on storing
43 delta frames this can only be key frame precise
44 frames (int) - the number of frames the chunk consists of
45 (by default all frames in the file)
60 def option(self, file = None, start = None, frames = None):
62 Change object properties
64 file (string) - the name of a video file
65 (changing this will reinitialize the object)
66 start (float) - the second which marks the start of the chunk
67 frames (int) - the number of frames the chunk consists of
71 rem_start = self.start
72 rem_frames = self.frames
75 self.start = rem_start
76 self.frames = rem_frames
86 this method is for internal use, calling it will stop the video and reset
87 the 'start' and 'frame' properties
91 self.slave = os.popen('mplayer -frames 0 -identify "'+self.videofile+'"')
92 line = self.slave.readline()
94 if line.find('ID_') == 0:
95 line = line.split('\n')[0]
96 [key, value] = line.split('=', 1)
97 self.videoprops[key] = value
98 line = self.slave.readline()
103 self.frames = int(float(self.videoprops['ID_VIDEO_FPS']) *
104 float(self.videoprops['ID_LENGTH'])
106 self.width = int(self.videoprops['ID_VIDEO_WIDTH'])
107 self.height = int(self.videoprops['ID_VIDEO_HEIGHT'])
109 def slave_video(self):
111 Return a list of mplayer command line arguments,
112 which specifies the video to play.
115 ['videofile', '-ss', start, '-frames', frames]
118 return [self.videofile,
119 '-ss', str(self.start),
120 '-frames', str(self.frames)