The GStreamer Development TeamJune ??, 20032003David I. Lehngst-python: A Python Interface to GStreamergst-pythonDavidI.Lehndlehn@users.sourceforge.netIntroductory information for the GStreamer Python bindings.0.1.02003-06-??dilInitial version.Aboutgst-python: the Python bindings for the GStreamer project. These bindings provide access to almost all of the GStreamer C API through an object oriented Python API.
NewsDateVersionNotes2003-06-xx0.1.0first releaseInstallationRequirements
Python 2.2 ()
GStreamer 0.6.x (except 0.6.1) ()
PyGTK 1.99.14 ()
Building and Installation
For build and install information please refer to the "INSTALL" file. Installation is optional, gst-python can be used from the build directory. The quick instructions: build and install PyGTK and GStreamer then build gst-python:
$ ./configure && make
Using
You either need to install the package or add the root directory to your
Python path:
$ export PYTHONPATH=$PYTHONPATH:`pwd`
Try running examples:
$ cd examples/gstreamer/
$ python cp.py <input file> <output file>
$ cmp <input file> <output file>
$ python vorbisplay.py <an Ogg Vorbis file>
ProgrammingGeneral API
The gst-python bindings are directly generated from the GStreamer headers. Look at the GStreamer documentation at for general API and programming issues. In most cases the GStreamer classes and boxed types map directly to Python classes. The function-based GObject methods also map onto Python methods.
Divergence From C APIDue to the nature of C and Python some of the GStreamer API is handled
slightly different in Python than C. There are a few of the GStreamer C
functions that are not yet provided in gst-python. These are mostly related to
creating . A
few others remain that return GList* or return values in their parameters.
These have been wrapped as needed. Please file a bug if you need one of the unwrapped functions.API changes:gst_props_entry_get_type is accessed
through PropsEntry.get_props_type(). This is due to the
_get_type function extention being normally used for
GType access and is inaccessable
otherwise.Special pipeline
iteration support through the following functions:add_iterate_bin(bin) -> id: used
to iterate a bin with a C idle loop callback instead of a Python
callback.remove_iterate_bin(id): used to remove the
add_iterate_bin idle loop callback
id.iterate_bin_all(bin): releases locks, calls
gst_bin_iterate until it returns 0, reacquires locks
and completesPython Elements support through the following currently horribly inefficient functions:Buffer.get_data() ->
string: converts buffer data to a string and
returns it.Buffer.set_data(string): sets the buffer data from a
string.ExamplesThe best documentation right now are the examples in ./examples/gstreamer/. Read them.ThreadsThreading is a tricky subject for gst-python. There are a few lock you
need to be aware of:GILThe CPython interpreter is single threaded. Code execution in the
interpreter is protected by a Global Interpreter Lock (GIL). This means that C
code can run in other threads in parallel but only one thread will be running
Python code at any one point. Most of this is handled internally by means of
locking and unlocking the GIL at appropriate times. Callback code and other
various code paths between Python and C *should* be setup to do proper GIL
handling.However, it is possible that you may encounter a situation where proper
locking is not done. This is most likely due to calling a wrapper function
that follows a sequence like this:Python calls wrapper functionwrapper function calls C GStreamer functionC GStreamer function calls side effect codeside effect code calls callbackcallback tries to acquire Python GIL but it's already lockeddeadlocked...This has been fixed for commonly called functions that have side effects
which are likely to re-enter the interpreter. It just involves lock/unlock
around the call to the C gst function. But doing it for every function could
have performance issues and, more importantly, is not an automated
process.Please file a bug if you have problems
related to this and need other functions to be specially handled.Gdk LockIf you are using PyGTK you will have to deal with Gdk locking. Make sure
you're holding the Gdk lock while executing Gdk/Gtk calls. See PyGTK
documentation and FAQ list for more information.Pipeline IterationThere are a number of ways to iterate pipelines.
./examples/gstreamer/bps.py is a small test program to
measure the performance in buffers per second of these various techniques.
Please see the example for how to use these techniques.Bin.iterate() in Python from the gtk idle loopgst_bin_iterate() in C from gtk idle loopBin.iterate() in a Python loopgst_bin_iterate() in a C loopThe method you chose depends on your application. The idle loop methods
are slightly slower yet more flexible. Probably useful for interactive GUI
applications.The basic loop methods are faster but probably more use for
non-interactive applications. A variation on these loops would be to also
check for a stop condition which may provide performance increase and some
level of control.Python Elements It is possible to write Python subclasses of GstElement. This support
is very primitive and likely to change. See
./examples/gstreamer/rot13.py for an example.BugsPlease submit gst-python bugs, patches, or suggestions to GNOME Bugzilla (). Product: GStreamer, Component: gst-python. Or alternatively send a message to the gstreamer-devel list or the maintainer. Thank you.
TODOhandle more of the functions that need manual wrapping codeadd check that pygtk built with --enable-threadimprove Python gstreamer.Element creationperhaps drop _set_foo_function() calls in favor of object methodssane buffer handling with buffer type or Numeric?docsAPI refmanualtutorialmore examplesconvert build system to distutilswrap other GStreamer helper libsadd some standard widgetsgtk video widget (similar to widget gst-player is using)testsuiteAuthors
Please feel free to contact the developers. They hang out on IRC () and the mailing lists ().
MaintainerDavid I. Lehn dlehn at users.sourceforge.netContributions
Patches, suggestions, and other help:
Kenichi Sato ksato at users.sourceforge.net
Much of the framework for gst-python stolen from gtk and gconf bindings by:
James Henstridge james at daa.com.auJohan Dahlin jdahlin at telia.comMatt Wilson msw at redhat.comand many more...GStreamer Team
And of course, none of this would be possible without the extreme hacker mojo
of the whole GStreamer crew!