Module MediaInfo
[hide private]
[frames] | no frames]

Source Code for Module MediaInfo

 1  #    This file is part of Subtle 
 2  # 
 3  #    This program is free software: you can redistribute it and/or modify 
 4  #    it under the terms of the GNU General Public License as published by 
 5  #    the Free Software Foundation, either version 3 of the License, or 
 6  #    (at your option) any later version. 
 7  # 
 8  #    This program is distributed in the hope that it will be useful, 
 9  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
10  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
11  #    GNU General Public License for more details. 
12  # 
13  #    You should have received a copy of the GNU General Public License 
14  #    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
15   
16  import os 
17  import pygtk 
18  pygtk.require('2.0') 
19  import gobject 
20  gobject.threads_init() 
21  import pygst 
22  pygst.require('0.10') 
23  import gst 
24  from gst.extend import discoverer 
25   
26 -class Media:
27 has_audio = None 28 has_video = None 29 framerate = None 30 sourceURI = None 31 MIME = None 32 videoLengthNS = None 33 videoLengthS = None 34 videoCaps = None 35 videoWidth = None 36 videoHeight = None
37
38 -class MediaInfo:
39
40 - def __init__(self, file, uri):
41 self.media = Media() 42 self.media.source = file 43 self.media.sourceURI = uri 44 self.discover(file) 45 self.notDone = True
46
47 - def discover(self,path):
48 d = discoverer.Discoverer(path) 49 d.connect('discovered',self.cb_discover) 50 d.discover()
51
52 - def cb_discover(self, d, ismedia):
53 if ismedia: 54 self.media.MIME = d.mimetype 55 if d.is_video: 56 self.media.has_video = True 57 self.media.framerate = float(d.videorate.num) \ 58 / float(d.videorate.denom) 59 self.media.videoLengthNS = d.videolength 60 self.media.videoLengthS = float(d.videolength) \ 61 / float(gst.MSECOND)/1000.0 62 self.media.videoCaps = d.videocaps 63 self.media.videoHeight = d.videoheight 64 self.media.videoWidth = d.videowidth 65 if d.is_audio: 66 self.media.has_audio = True 67 self.notDone = False
68
69 - def poll(self):
70 return self.notDone
71
72 - def getMedia(self):
73 return self.media
74