Question

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"?

Was it helpful?

Solution

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%\lib\gstreamer-0.10
    Path=%GSTREAMER_SDK_ROOT_X86%\bin;%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% \lib\python2.7\site-packages
    ..your %GSTREAMER_SDK_ROOT_X86% \lib\python2.7\site-packages\gst-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%\lib\gstreamer-1.0\
    Path=%GSTREAMER_1_0_ROOT_X86%\bin;%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%\bin
    %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

OTHER TIPS

Step 1: Windows 8.1 64-bit

Step 2: Download and Install Python

C:\>wget https://www.python.org/ftp/python/2.7.9/python-2.7.9.amd64.msi
C:\>./python-2.7.9.amd64.msi
C:\>cd C:\Python27
C:\>pwd
C:\Python27

Step 3: Download install Python bindings for Gstreamer 1.0

C:\>wget http://sourceforge.net/projects/pygobjectwin32/files/pygi-aio-3.14.0_rev14-setup.exe
C:\>unzip "pygi-aio-3.14.0_rev14-setup.exe"
C:\>whereis_unzipped "pygi-aio-3.14.0_rev14-setup.exe"
C:\pygi
C:\>./c:\pygi\setup.exe

enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here

Step 4: Run this code

C:\>C:\Python27\python.exe -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)"

Step 5: You have to wait 10 minutes, to see a result similar to following. Because it takes time for some reason

enter image description here

The installer from http://sourceforge.net/projects/pygobjectwin32/files/ should works for the test case that Tom gave. Try to match which plugins installed by pygi installer with the one from official gstreamer.

The installer try to be a "portable and private" installation for each python without registry/environmen vars changes.

My note about the runtime dlls, it's recommended not to mixing the runtime cause the one from pygi is made specifically for python a.k.a linked to msvcrt preferred by python, and use stat() convention that used by python too. If a public api such glib's stat() use different convention than other dll then a runtime mixing could lead to a silent crash. Other than that it may works fine though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top