From d8313145546a35f3cc92e5316f840a481e373f0d Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 8 Mar 2012 20:45:02 +0100 Subject: [PATCH] add center mode --- bin/oxtimeline | 3 ++- oxtimeline/video.py | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/oxtimeline b/bin/oxtimeline index fc0d676..0562a2e 100755 --- a/bin/oxtimeline +++ b/bin/oxtimeline @@ -24,6 +24,7 @@ if __name__ == '__main__': parser.add_option('-y', '--height', dest='height', help='timeline height, defaults to 64px', default=64, type="int") parser.add_option('-o', '--prefix', dest='prefix', help='prefix for timeline tiles') parser.add_option('-i', '--input', dest='input', help='video input') + parser.add_option('-m', '--mode', dest='mode', default='average', help='timeline mode: average(default), center') parser.add_option('-a', '--audio', action="store_true", dest="audio", default=False) (opts, args) = parser.parse_args() @@ -39,7 +40,7 @@ if __name__ == '__main__': if not info['video'] or opts.audio: audio.Timeline(opts.input, opts.prefix, opts.width, opts.height) else: - video.Timeline(opts.input, opts.prefix, opts.width, opts.height) + video.Timeline(opts.input, opts.prefix, opts.width, opts.height, opts.mode) #oxtimeline.createTimelineMultiline(opts.prefix) oxtimeline.makeTiles(opts.prefix, 16, 3600) diff --git a/oxtimeline/video.py b/oxtimeline/video.py index da51b53..8923cad 100644 --- a/oxtimeline/video.py +++ b/oxtimeline/video.py @@ -4,7 +4,6 @@ from __future__ import division import Image -import time import math import gobject @@ -80,10 +79,11 @@ class Timeline(Video): _ready = False lastPos=0 timeline_fps = 25 + mode = 'average' - def __init__(self, uri, prefix, width, height): + def __init__(self, uri, prefix, width, height, mode): Video.__init__(self, uri, height, gst.Fraction(self.timeline_fps, 1)) - + self.mode = mode bus = self.get_bus() bus.add_signal_watch() self.watch_id = bus.connect("message", self.onBusMessage) @@ -127,7 +127,13 @@ class Timeline(Video): self._ready = True else: _framePos = int(math.ceil((float(timestamp) / (gst.SECOND) * float(self.framerate)))) + 1 - frame = frame.resize((1, self.tile_height), Image.ANTIALIAS) + if self.mode == 'center': + frame = frame.crop((int(frame.size[1]/2), 0, + int(frame.size[1]/2)+1, frame.size[0])) + frame = frame.resize((1, self.tile_height), Image.ANTIALIAS) + else: + frame = frame.resize((1, self.tile_height), Image.ANTIALIAS) + for framePos in range(self.lastPos, _framePos): tile = int(math.floor(float(framePos) / self.input_tile_width)) tilePos = framePos - (tile * self.input_tile_width)