Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
389 views
in Technique[技术] by (71.8m points)

gstreamer python bindings for windows

I am looking into gstreamer as a means to choose a video device from a list to feed it to an opencv script.

I absolutely do not understand how to use gstreamer with python in windows. I installed the Windows gstreamer 1.07 binaries from the gstreamer official website. However, I could not import the pygst and gst modules in python.

>>> import pygst

Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pygst
ImportError: No module named pygst
>>> 

I checked the gstreamer installation, and there seems to be no pygst.py provided. There is however a file named gst-env that contains paths for environnement variables (that were not added to the system variables on installation. I checked.

Other questions on the same problem here and here, for example, do all use the winbuild versions of gstreamer. Why is that so?

I am totally lost on this one.

Edit

Ok, I managed it using the SDK for Gstreamer 0.10 (in which there is a pygst.py), but is there not a way to use the Gstreamer 1.0 series, since 0.10 is "end-of-life"?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is a bit late, but hopefully it will help.

The easiest way to use GStreamer 1.0 is to download the latest version from: http://sourceforge.net/projects/pygobjectwin32/files/

This will install Python (2.7 or 3.3) modules and, optionally, GStreamer with plugins.

However, if you already have GStreamer 0.10 SDK (from docs.gstreamer.com/display/GstSDK/Home) and old installation of GStreamer 1.0 somewhere, there might be some problems with running Gstreamer 0.10 Python programs, like ImportError: DLL load failed etc. Here's my detailed setup for everything:

Installation of Gst 0.10 SDK and Python modules

  1. Install SDK from docs.gstreamer.com/display/GstSDK/Installing+on+Windows. Check and set environment variables
    GSTREAMER_SDK_ROOT_X86=..your sdk dir
    GST_PLUGIN_PATH=%GSTREAMER_SDK_ROOT_X86%libgstreamer-0.10
    Path=%GSTREAMER_SDK_ROOT_X86%in;%GSTREAMER_SDK_ROOT_X86%lib;%Path%
  2. Install pygtk-all-in-one-2.24.2.win32-py2.7 from ftp.gnome.org/pub/GNOME/binaries/win32/
  3. In your Python site-packages dir create file pygst.pth. Put following lines, which should point to GSt 0.10 Python modules directories:
    ..your %GSTREAMER_SDK_ROOT_X86% libpython2.7site-packages
    ..your %GSTREAMER_SDK_ROOT_X86% libpython2.7site-packagesgst-0.10
  4. After that, pydoc should be able to find documentation for pygst, gst, etc. Also, intellisense in Python tools for Visual studio should work too (after rebuilding Completion DB and restarting VS)

Installation of Gst 1.0 and Python modules

  1. Install GStreamer 1.0 from gstreamer.freedesktop.org/data/pkg/windows/. Check environment:
    GSTREAMER_1_0_ROOT_X86=..Gst 1.0 installation dir
    GST_PLUGIN_PATH_1_0=%GSTREAMER_1_0_ROOT_X86%libgstreamer-1.0
    Path=%GSTREAMER_1_0_ROOT_X86%in;%GSTREAMER_1_0_ROOT_X86%lib;%Path%
  2. Install pygi-aio-3.10.2-win32_rev14-setup from the above Sourceforge link. Include Gstreamer and plugins in the installation.
  3. Create file gi.pth:
    %GSTREAMER_1_0_ROOT_X86%in
    %GSTREAMER_1_0_ROOT_X86%lib
  4. I removed everything from the site-packages/gnome directory except:
    libgirepository-1.0-1
    libpyglib-gi-2.0-python27-0
    lib directory with the .typelib files
    and a few simple examples seem to work fine.
  5. Intellisense in VS doesn't seem to work for imports from gi.repository.
  6. You may test your installation like this:

    python2 -c "import gi; gi.require_version('Gst', '1.0'); from gi.repository import Gst; Gst.init(None); pipeline = Gst.parse_launch('playbin uri=http://docs.gstreamer.com/media/sintel_trailer-480p.webm'); pipeline.set_state(Gst.State.PLAYING); bus = pipeline.get_bus();msg = bus.timed_pop_filtered(Gst.CLOCK_TIME_NONE, Gst.MessageType.ERROR | Gst.MessageType.EOS)"

Edit: If you use both GStreamer0.10 and GStreamer1.0 it's better to create a separate virtual environment for GStreamer0.10 and put .pth files in its site-packages directory. See my comment below.

HTH, Tom


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...