1
# Copyright (C) 2008 Michael Charclo
3
# This program is free software; you can redistribute it and/or
4
# modify it under the terms of the GNU General Public License
5
# as published by the Free Software Foundation; either version 2
6
# of the License, or (at your option) any later version.
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.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
"""This is the videofile class"""
23
__LOGFILE = os.path.expanduser("~/.encoder/logfile")
25
def __init__(self, filename):
26
self.filename = filename
30
self.audio_codec = 'N/A'
34
def get_metadata(self):
36
Get the metadata from a Video File
38
To get the metadata from the Video File we let ffmpeg try to convert it
39
to a non-existant location. The resulting info is scanned for metadata.
42
#FIXME: This method could probably be done better with pymedia... or not?
43
pipe = os.popen('''ffmpeg -i "%s" /dev/null &> %s''' %(self.filename, self.__LOGFILE))
45
f = file(self.__LOGFILE)
48
regexp = r'''Duration:\s(?P<hours>\d{2}):(?P<minutes>\d{2}):(?P<seconds>\d{2}.\d),'''
49
match = re.search(regexp, logfile)
50
self.hours = int(match.group('hours'))
51
self.minutes = int(match.group('minutes'))
52
self.seconds = float(match.group('seconds'))
53
self.duration = '%d:%d:%.f' %(self.hours, self.minutes, self.seconds)
55
regexp = r'''bitrate:\s(?P<video_bitrate>.*?)\s'''
56
match = re.search(regexp, logfile)
57
self.video_bitrate = match.group('video_bitrate')
59
regexp = r'''Video:\s(?P<video_codec>.*?),'''
60
match = re.search(regexp, logfile)
61
self.video_codec = match.group('video_codec')
63
regexp = r'''\s(?P<width>\d*?)x(?P<height>\d*?),'''
64
match = re.search(regexp, logfile)
65
self.width = match.group('width')
66
self.height = match.group('height')
67
self.size = self.width + 'x' + self.height
69
## self.aspect = str(float(match.group('width'))/float(match.group('height')))[:6]
72
regexp = r'''\s(?P<fps>\d{1,2}\.\d{1,2})\sfps'''
73
match = re.search(regexp, logfile)
74
self.fps = float(match.group('fps'))
76
regexp = r'''Audio:\s(?P<audio_codec>.*?),'''
77
match = re.search(regexp, logfile)
78
self.audio_codec = match.group('audio_codec')
80
regexp = r'''Hz,\s(?P<mono_stereo>.*?),'''
81
match = re.search(regexp, logfile)
82
self.mono_stereo = match.group('mono_stereo')
84
regexp = r''',\s(?P<audio_bitrate>\d{2,3})\skb/s'''
85
match = re.search(regexp, logfile)
86
self.audio_bitrate = match.group('audio_bitrate')
90
self.metadata = [self.duration, self.video_bitrate\
91
, self.video_codec, self.size, self.fps, self.audio_codec\
92
, self.mono_stereo, self.audio_bitrate]
95
def get_filename(self):
98
## def get_hours(self):
101
## def get_minutes(self):
102
## return self.minutes
104
## def get_seconds(self):
105
## return self.seconds
b'\\ No newline at end of file'