mirror of
https://github.com/gryf/pygtktalog.git
synced 2025-12-17 11:30:19 +01:00
Separated code for geting information about movie, minor fixes
This commit is contained in:
@@ -30,8 +30,8 @@ class Video(object):
|
|||||||
|
|
||||||
attrs = {'ID_VIDEO_WIDTH': ['width', int],
|
attrs = {'ID_VIDEO_WIDTH': ['width', int],
|
||||||
'ID_VIDEO_HEIGHT': ['height', int],
|
'ID_VIDEO_HEIGHT': ['height', int],
|
||||||
'ID_LENGTH': ['length', lambda x: int(x.split(".")[0])],
|
|
||||||
# length is in seconds
|
# length is in seconds
|
||||||
|
'ID_LENGTH': ['length', lambda x: int(x.split(".")[0])],
|
||||||
'ID_DEMUXER': ['container', str],
|
'ID_DEMUXER': ['container', str],
|
||||||
'ID_VIDEO_FORMAT': ['video_format', str],
|
'ID_VIDEO_FORMAT': ['video_format', str],
|
||||||
'ID_VIDEO_CODEC': ['video_codec', str],
|
'ID_VIDEO_CODEC': ['video_codec', str],
|
||||||
@@ -44,14 +44,13 @@ class Video(object):
|
|||||||
if key in attrs:
|
if key in attrs:
|
||||||
self.tags[attrs[key][0]] = attrs[key][1](output[key])
|
self.tags[attrs[key][0]] = attrs[key][1](output[key])
|
||||||
|
|
||||||
if 'length' in self.tags:
|
if 'length' in self.tags and self.tags['length'] > 0:
|
||||||
if self.tags['length'] > 0:
|
hours = self.tags['length'] / 3600
|
||||||
hours = self.tags['length'] / 3600
|
seconds = self.tags['length'] - hours * 3600
|
||||||
seconds = self.tags['length'] - hours * 3600
|
minutes = seconds / 60
|
||||||
minutes = seconds / 60
|
seconds -= minutes * 60
|
||||||
seconds -= minutes * 60
|
length_str = "%02d:%02d:%02d" % (hours, minutes, seconds)
|
||||||
length_str = "%02d:%02d:%02d" % (hours, minutes, seconds)
|
self.tags['duration'] = length_str
|
||||||
self.tags['duration'] = length_str
|
|
||||||
|
|
||||||
def capture(self, out_width=1024):
|
def capture(self, out_width=1024):
|
||||||
"""
|
"""
|
||||||
@@ -67,22 +66,30 @@ class Video(object):
|
|||||||
other place, otherwise it stays in filesystem.
|
other place, otherwise it stays in filesystem.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not (self.tags.has_key('length') or self.tags.has_key('width')):
|
if not (self.tags.has_key('length') and self.tags.has_key('width')):
|
||||||
|
# no length or width
|
||||||
|
return None
|
||||||
|
|
||||||
|
if not (self.tags['length'] >0 and self.tags['width'] >0):
|
||||||
|
# zero length or wight
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Calculate number of pictures. Base is equivalent 72 pictures for
|
# Calculate number of pictures. Base is equivalent 72 pictures for
|
||||||
# 1:30:00 movie length
|
# 1:30:00 movie length
|
||||||
scale = int(10 * math.log(self.tags['length'], math.e) - 11)
|
scale = int(10 * math.log(self.tags['length'], math.e) - 11)
|
||||||
no_pictures = self.tags['length'] / scale
|
|
||||||
if no_pictures > 8:
|
|
||||||
# for really short movies
|
|
||||||
no_pictures = (no_pictures / 8 ) * 8 # only multiple of 8, please.
|
|
||||||
|
|
||||||
if not no_pictures:
|
print "***", scale
|
||||||
# movie too short or length is 0
|
if scale < 1:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if no_pictures < 4:
|
no_pictures = self.tags['length'] / scale
|
||||||
|
|
||||||
|
print "no_pictures: ", no_pictures
|
||||||
|
|
||||||
|
if no_pictures > 8:
|
||||||
|
no_pictures = (no_pictures / 8 ) * 8 # only multiple of 8, please.
|
||||||
|
else:
|
||||||
|
# for really short movies
|
||||||
no_pictures = 4
|
no_pictures = 4
|
||||||
|
|
||||||
tempdir = mkdtemp()
|
tempdir = mkdtemp()
|
||||||
|
|||||||
Reference in New Issue
Block a user