forked from 0x2620/pandora
only open timelines needed to computed average color for clips
This commit is contained in:
parent
121d2e30dc
commit
88b4d9f62f
3 changed files with 8 additions and 7 deletions
|
@ -161,5 +161,5 @@ class Annotation(models.Model):
|
|||
return j
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s/%s-%s" %(self.item, self.start, self.end)
|
||||
return u"%s %s-%s" %(self.public_id, self.start, self.end)
|
||||
|
||||
|
|
|
@ -294,11 +294,12 @@ def average_color(prefix, start=0, end=0):
|
|||
timelines = sorted(filter(lambda t: t!= '%s%sp.png'%(prefix,height), glob("%s%sp*.png"%(prefix, height))))
|
||||
for image in timelines:
|
||||
start_offset = 0
|
||||
timeline = Image.open(image).convert('RGB')
|
||||
frames += timeline.size[0]
|
||||
if start and frames < start:
|
||||
if start and frames + 1500 < start:
|
||||
frames += 1500
|
||||
continue
|
||||
elif start and frames > start > frames-timeline.size[0]:
|
||||
timeline = Image.open(image)
|
||||
frames += timeline.size[0]
|
||||
if start and frames > start > frames-timeline.size[0]:
|
||||
start_offset = start - (frames-timeline.size[0])
|
||||
box = (start_offset, 0, timeline.size[0], height)
|
||||
timeline = timeline.crop(box)
|
||||
|
@ -307,7 +308,7 @@ def average_color(prefix, start=0, end=0):
|
|||
box = (0, 0, end_offset, height)
|
||||
timeline = timeline.crop(box)
|
||||
|
||||
p = np.asarray(timeline, dtype=np.float32)
|
||||
p = np.asarray(timeline.convert('RGB'), dtype=np.float32)
|
||||
p = np.sum(p, axis=0) / height #average color per frame
|
||||
pixels.append(p)
|
||||
|
||||
|
|
|
@ -935,7 +935,7 @@ class Item(models.Model):
|
|||
|
||||
def make_timeline(self):
|
||||
streams = self.streams()
|
||||
if len(streams) > 1:
|
||||
if streams.count() > 1:
|
||||
timelines = [s.timeline_prefix for s in self.streams()]
|
||||
join_timelines(timelines, self.timeline_prefix)
|
||||
|
||||
|
|
Loading…
Reference in a new issue