fix 64px timelines

This commit is contained in:
j 2010-08-20 12:11:17 +02:00
parent 095da90eec
commit 83db829cf8
3 changed files with 40 additions and 16 deletions

View File

@ -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

View File

@ -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()

View File

@ -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)))