From 83db829cf8dec41f6a4a3908991952f9b90d2cb3 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 20 Aug 2010 12:11:17 +0200 Subject: [PATCH] fix 64px timelines --- oxgst/singledecodebin.py | 19 +++++++++++++++++++ oxgst/timeline.py | 25 ++++++++++++------------- oxgst/video.py | 12 +++++++++--- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/oxgst/singledecodebin.py b/oxgst/singledecodebin.py index bda5a96..d046f2d 100644 --- a/oxgst/singledecodebin.py +++ b/oxgst/singledecodebin.py @@ -29,6 +29,25 @@ import gobject import gst +def pad_compatible_stream(pad, stream): + """ + Checks whether the given pad is compatible with the given stream. + + @param pad: The pad + @type pad: C{gst.Pad} + @param stream: The stream to match against. + @type stream: L{MultimediaStream} + @return: Whether the pad is compatible with the given stream + @rtype: C{bool} + """ + if stream == None: + # yes, None is the magical stream that takes everything + return True + # compatible caps + if stream.caps: + return not stream.caps.intersect(pad.get_caps()).is_empty() + raise Exception("Can't figure out compatibility since the stream doesn't have any caps") + class CachedFactoryList(object): def __init__(self, factoryFilter=None): self._factoryFilter = factoryFilter diff --git a/oxgst/timeline.py b/oxgst/timeline.py index 2fd4bfa..0506fd7 100644 --- a/oxgst/timeline.py +++ b/oxgst/timeline.py @@ -1,6 +1,6 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -# vi:si:et:sw=4:sts=4:ts=4 +# -*- coding: utf-8 -*- +# vi:si:et:sw=4:sts=4:ts=4 # GPL 2008 import gobject gobject.threads_init() @@ -21,8 +21,9 @@ from video import Video class Timeline(Video): + lastPos=0 def __init__(self, uri): - Video.__init__(self, uri) + Video.__init__(self, uri, '25/1') bus = self.get_bus() bus.add_signal_watch() @@ -63,10 +64,6 @@ class Timeline(Video): def done(self): self.mainloop.quit() - def _sbinPadAddedCb(self, unused_sbin, pad): - self.log("pad : %s" % pad) - pad.link(self.csp.get_pad("sink")) - def _frameCb(self, unused_thsink, frame, timestamp): self.log("image:%s, timestamp:%s" % (frame, gst.TIME_ARGS(timestamp))) @@ -74,13 +71,15 @@ class Timeline(Video): # we know we're prerolled when we get the initial thumbnail self._ready = True else: - framePos = int(math.ceil((float(timestamp) / (gst.SECOND) * float(self.framerate)))) - tile = int(math.floor(float(framePos) / self.input_tile_width)) - tilePos = framePos - (tile * self.input_tile_width) - frame = frame.resize((1, self.tile_height), Image.ANTIALIAS) - for i in range(self.tile_height): - self.tiles[tile].putpixel((tilePos, i), frame.getpixel((0, i))) + _framePos = int(math.ceil((float(timestamp) / (gst.SECOND) * float(self.framerate)))) + for framePos in range(self.lastPos, _framePos): + tile = int(math.floor(float(framePos) / self.input_tile_width)) + tilePos = framePos - (tile * self.input_tile_width) + frame = frame.resize((1, self.tile_height), Image.ANTIALIAS) + for i in range(self.tile_height): + self.tiles[tile].putpixel((tilePos, i), frame.getpixel((0, i))) + self.lastPos = _framePos if self.mainloop and timestamp >= self.duration: self.done() diff --git a/oxgst/video.py b/oxgst/video.py index 1550076..cc8b753 100644 --- a/oxgst/video.py +++ b/oxgst/video.py @@ -17,7 +17,7 @@ from imagesink import ImageSink class Video(gst.Pipeline): - def __init__(self, uri): + def __init__(self, uri, framerate='25/1'): gst.Pipeline.__init__(self) self.duration = -1 # queue of timestamps @@ -37,10 +37,16 @@ class Video(gst.Pipeline): self.sbin = SingleDecodeBin(caps=gst.Caps("video/x-raw-rgb;video/x-raw-yuv"), uri=self.uri) self.csp = gst.element_factory_make("ffmpegcolorspace") + self.rate = gst.element_factory_make("videorate") + self.queue = gst.element_factory_make("queue") + self.sink = ImageSink() self.sink.connect('frame', self._frameCb) - self.add(self.sbin, self.csp, self.sink) + self.add(self.sbin, self.csp, self.queue, self.rate, self.sink) + + self.queue.link(self.rate) + self.rate.link(self.csp, gst.Caps("video/x-raw-yuv,framerate=%s"%framerate)) self.csp.link(self.sink) self.sbin.connect('pad-added', self._sbinPadAddedCb) @@ -54,7 +60,7 @@ class Video(gst.Pipeline): def _sbinPadAddedCb(self, unused_sbin, pad): self.log("pad : %s" % pad) - pad.link(self.csp.get_pad("sink")) + pad.link(self.queue.get_pad("sink")) def _frameCb(self, unused_thsink, frame, timestamp): self.log("image:%s, timestamp:%s" % (frame, gst.TIME_ARGS(timestamp)))