save color/cuts per stream

This commit is contained in:
j 2011-10-21 20:02:36 +02:00
parent 1bec444f66
commit b9b861a3e8
2 changed files with 21 additions and 2 deletions

View file

@ -442,6 +442,9 @@ class Stream(models.Model):
duration = models.FloatField(default=0)
aspect_ratio = models.FloatField(default=0)
cuts = fields.TupleField(default=[])
color = fields.TupleField(default=[])
@property
def timeline_prefix(self):
return os.path.join(settings.MEDIA_ROOT, self.path(), 'timeline')
@ -484,6 +487,8 @@ class Stream(models.Model):
def make_timeline(self):
if self.available and not self.source:
extract.timeline(self.video.path, self.timeline_prefix)
self.cuts = tuple(extract.cuts(self.timeline_prefix))
self.color = tuple(extract.average_color(self.timeline_prefix))
def save(self, *args, **kwargs):
if self.video and not self.info:

View file

@ -850,8 +850,22 @@ class Item(models.Model):
def update_timeline(self, force=False):
streams = self.streams()
self.make_timeline()
self.data['cuts'] = extract.cuts(self.timeline_prefix)
self.data['color'] = extract.average_color(self.timeline_prefix)
if streams.count() == 1:
self.data['color'] = streams[0].color
self.data['cuts'] = streams[0].cuts
else:
#self.data['color'] = extract.average_color(self.timeline_prefix)
#self.data['cuts'] = extract.cuts(self.timeline_prefix)
self.data['cuts'] = []
offset = 0
color = [0, 0, 0]
n = streams.count()
for s in streams:
for c in s.cuts:
self.data['cuts'].append(c+offset)
color = map(lambda a,b: (a+b)/n, color,ox.image.getRGB(s.color))
offset += s.duration
self.data['color'] = ox.image.getHSL(color)
#extract.timeline_strip(self, self.data['cuts'], stream.info, self.timeline_prefix[:-8])
self.select_frame()
self.make_local_poster()