Created
April 12, 2010 20:27
-
-
Save spiderbit/363961 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- Mode: Python -*- | |
# vi:si:et:sw=4:sts=4:ts=4 | |
# sinkelement.py | |
# (c) 2005 Edward Hervey <[email protected]> | |
# (c) 2007 Jan Schmidt <[email protected]> | |
# Licensed under LGPL | |
# | |
# Small test application to show how to write a sink element | |
# in 20 lines in python and place into the gstreamer registry | |
# so it can be autoplugged or used from parse_launch. | |
# | |
# Run this script with GST_DEBUG=python:5 to see the debug | |
# messages | |
import pygst | |
pygst.require('0.10') | |
import gst | |
from PIL import Image | |
import gobject | |
gobject.threads_init () | |
# | |
# Simple Sink element created entirely in python | |
# | |
class MySink(gst.Element): | |
__gstdetails__ = ('CustomSink','Sink', \ | |
'Custom test sink element', 'Edward Hervey') | |
_sinkpadtemplate = gst.PadTemplate ("sinkpadtemplate", | |
gst.PAD_SINK, | |
gst.PAD_ALWAYS, | |
gst.caps_new_any()) | |
def __init__(self): | |
gst.Element.__init__(self) | |
gst.info('creating sinkpad') | |
self.sinkpad = gst.Pad(self._sinkpadtemplate, "sink") | |
gst.info('adding sinkpad to self') | |
self.add_pad(self.sinkpad) | |
gst.info('setting chain/event functions') | |
self.sinkpad.set_chain_function(self.chainfunc) | |
self.sinkpad.set_event_function(self.eventfunc) | |
def chainfunc(self, pad, buffer): | |
self.info("%s timestamp(buffer):%d" % (pad, buffer.timestamp)) | |
print "a" | |
#im = Image.open("/home/black/foo.png") | |
print buffer.size | |
#help(buffer.data) | |
#help(Image) | |
im = Image.frombuffer(None, buffer.size, buffer.data, 'raw', 0, 1) | |
im.save("/home/black/foo-image.png") | |
print "b" | |
print type(im) | |
return gst.FLOW_OK | |
def eventfunc(self, pad, event): | |
self.info("%s event:%r" % (pad, event.type)) | |
return True | |
gobject.type_register(MySink) | |
# Register the element into this process' registry. | |
gst.element_register (MySink, 'mysink', gst.RANK_MARGINAL) | |
print "Use --gst-debug=python:3 to see output from this example" | |
# | |
# Code to test the MySink class | |
# | |
gst.info('About to create MySiself.player = gst.element_factory_make("playbin2", "player")nk') | |
sink = gst.element_factory_make("mysink", "sink") | |
player = gst.element_factory_make("playbin2", "player") | |
#player.set_property("video-sink", sink) | |
#player.set_property("uri", "file://" + "/home/black/bla.mpeg") | |
pipeline = gst.parse_launch ("videotestsrc ! video/x-raw-yuv ! ffmpegcolorspace ! mysink") | |
player.set_state(gst.STATE_PLAYING) | |
pipeline.set_state(gst.STATE_PLAYING) | |
gobject.MainLoop().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment