1
# PiTiVi , Non-linear video editor
3
# pitivi/elements/thumbnailsink.py
5
# Copyright (c) 2005, Edward Hervey <bilboed@bilboed.com>
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU Lesser General Public
9
# License as published by the Free Software Foundation; either
10
# version 2.1 of the License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
# Lesser General Public License for more details.
17
# You should have received a copy of the GNU Lesser General Public
18
# License along with this program; if not, write to the
19
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20
# Boston, MA 02110-1301, USA.
22
GdkPixbuf thumbnail sink
29
from pitivi.utils import big_to_cairo_alpha_mask, big_to_cairo_red_mask, big_to_cairo_green_mask, big_to_cairo_blue_mask
32
class CairoSurfaceThumbnailSink(gst.BaseSink):
34
GStreamer thumbnailing sink element.
36
Can be used in pipelines to generates gtk.gdk.Pixbuf automatically.
40
"thumbnail": (gobject.SIGNAL_RUN_LAST,
42
(gobject.TYPE_PYOBJECT, gobject.TYPE_UINT64))
46
gst.PadTemplate("sink",
49
gst.Caps("video/x-raw-rgb,"
50
"bpp = (int) 32, depth = (int) 32,"
51
"endianness = (int) BIG_ENDIAN,"
52
"alpha_mask = (int) %i, "
53
"red_mask = (int) %i, "
54
"green_mask = (int) %i, "
55
"blue_mask = (int) %i, "
56
"width = (int) [ 1, max ], "
57
"height = (int) [ 1, max ], "
58
"framerate = (fraction) [ 0, max ]"
59
% (big_to_cairo_alpha_mask,
60
big_to_cairo_red_mask,
61
big_to_cairo_green_mask,
62
big_to_cairo_blue_mask)))
66
gst.BaseSink.__init__(self)
71
def do_set_caps(self, caps):
72
self.log("caps %s" % caps.to_string())
73
self.log("padcaps %s" % self.get_pad("sink").get_caps().to_string())
74
self.width = caps[0]["width"]
75
self.height = caps[0]["height"]
76
if not caps[0].get_name() == "video/x-raw-rgb":
80
def do_render(self, buf):
81
self.log("buffer %s %d" % (gst.TIME_ARGS(buf.timestamp),
85
pixb = cairo.ImageSurface.create_for_data(b,
86
# We don't use FORMAT_ARGB32 because Cairo uses premultiplied
87
# alpha, and gstreamer does not. Discarding the alpha channel
88
# is not ideal, but the alternative would be to compute the
89
# conversion in python (slow!).
95
self.emit('thumbnail', pixb, buf.timestamp)
98
def do_preroll(self, buf):
99
return self.do_render(buf)
101
gobject.type_register(CairoSurfaceThumbnailSink)