]> git.plutz.net Git - viper/blob - frameset.py
implemeted most basic cropping controls
[viper] / frameset.py
1 #encoding: utf-8
2 #Copyright 2009 Paul Hänsch
3
4 #This file is part of Viper.
5
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.
10
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.
15
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/>
18
19 from chunk import *
20 from flic import *
21
22 class Frameset(Flic):
23     """
24     A set of single frames.
25
26     The frames are stored on harddisk and advanced editing operations can be
27     performed on the set. This object requires a project folder on the harddisk
28     where the frames can be stored.
29     """
30
31     def __init__(self, projectdir, chunk):
32         """
33         Constructor
34         
35         projectdir - path of the existing project directory, a subdirectory will 
36                      be created for each Frameset object
37         chunk      - a Chunk object from which the frameset will be created
38         """
39         Flic.__init__(self)
40         self.projectdir = ''
41         self.subdir = ''
42         self.frames = []
43         self.fps = 0
44         
45         if projectdir[-1] == '/':
46             self.projectdir = projectdir
47         else:
48             self.projectdir = projectdir + '/'
49
50         self.subdir = chunk.videofile + ":" + str(chunk.start) + ":" + str(chunk.frames) + '/'
51         try:
52             os.mkdir(self.projectdir + self.subdir)
53         except:
54             print 'subdirectory seems to exist, ignoring'
55
56         self.width = int(chunk.videoprops['ID_VIDEO_WIDTH'])
57         self.height = int(chunk.videoprops['ID_VIDEO_HEIGHT'])
58         self.fps = float(chunk.videoprops['ID_VIDEO_FPS'])
59
60         self.framegen(self.projectdir + self.subdir, chunk)
61
62     def framegen(self, dir, chunk):
63         """
64         Generate the frameset from chunk
65
66         This method is normally called by the constructor.
67         """
68         slave = None
69         cwd = os.getcwd()
70         os.chdir(dir)
71
72         slave = os.popen('mplayer -vf format=bgr24 -vo tga "' + 
73                          cwd + '/"' + chunk.slave_subcommand())
74         line = slave.readline()
75         while line != '':
76             print line
77             line = slave.readline()
78
79         for file in os.listdir('./'):
80             if file[-4:] == '.tga':
81                 self.frames.append(file)
82
83         os.chdir(cwd)
84
85     def slave_video(self):
86         """
87         Return a list of mplayer command line arguments,
88         which specifies the video to play.
89
90         In this case:
91         ['mf://images', '-mf', 'fps={framerate}'
92         """
93         return ('mf://' + self.projectdir + self.subdir + '*.tga',
94                 '-mf', 'fps=' + str(self.fps)
95                 )