add center mode
This commit is contained in:
parent
0f3045f829
commit
d831314554
2 changed files with 12 additions and 5 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue