8

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

Community
  • 1
  • 1
Raoul
  • 1,744
  • 3
  • 22
  • 44
  • the sdk for gstreamer-1.0 is still work in progress. – ensonic Jun 25 '13 at 17:35
  • @ensonic: the following answer is not anymore working with Python 2.7x and Gstreamer 1.x in Windows 8.1 64-bit. Can anyone please post a proper answer about it. –  Apr 01 '15 at 11:36

3 Answers3

13

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

  • How do I make a .pth file? And what does it do? – Prakhar Mohan Srivastava Feb 11 '14 at 03:42
  • You can use any text editor. From: http://docs.python.org/2/library/site.html _A path configuration file is a file whose name has the form name.pth and exists in one of the four directories mentioned above; its contents are additional items (one per line) to be added to sys.path. _ –  Feb 11 '14 at 20:36
  • A few notes on Tom's procedure: 1- Make sure you _do_ update the system path by typing "echo %path%" in your cmd. 2- For GStreamer 0.10 with today's version of the GStreamer SDK, downloading and installing pygtk-all-in-one-2.24.2.win32-py2.7 _broke_ everything (Windows 8 FYI). The SDK already contains gtk. (check lib/python2.7/site-package) - I am not sure that adding %GSTREAMER_SDK_ROOT_X86% \lib\python2.7\site-packages\gst-0.10 is required, since you use gst by calling pygst.require('0.10') 3- Last point: a big THANK YOU because I have been trying for days. – Flavian Hautbois Feb 19 '14 at 14:48
  • There is more though. If you don't add the bin and lib paths to the _start_ of your path (namely Path=%Path%;%GSTREAMER_SDK_ROOT_X86%\bin;%GSTREAMER_SDK_ROOT_X86%\lib) you might get the following error: "Couldn't reserve space for cygwin's heap, Win32 error 0". – Flavian Hautbois Feb 19 '14 at 15:32
  • 1
    Yes, in the meantime, I also had some problems with this setup. Finally I created a separate virtualenv for Gst0.10, which only needs the .pth files in its site-packages directory (as above), and installed Gst1.0 from all-in-one package in the default Python installation. The other possible solution is to use Python 2.7 for Gst0.10 and Python 3.x for Gst1.0. Python tools for VS, thankfully, handle all this very nicely. I think I added %GSTREAMER_SDK_ROOT_X86% \lib\python2.7\site-packages\gst-0.10 in the .pth file to get intellisense for the gst in the VS Pytools. –  Feb 20 '14 at 00:42
  • Please check my answer and can you please explain why its taking 10 to 20 minutes for showing the result? http://stackoverflow.com/a/29390201/285594 –  Apr 01 '15 at 11:58
3

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

  • 1
    I tried your example, with fresh install of Python (32bit) and pygi-aio on Win81 64bit. The first time I tried it took quite a long time on Gst.init(None), but later it didn't. I don't remember was it the same at the time I wrote this. However, now it breaks on the _parse_launch('playbin...')_ statement, and also _'gst-launch playbin ...'_ crashes. Probably missing something from the path –  Apr 02 '15 at 19:57
  • Sorry, I have nothing with Gstreamer team :) –  Apr 03 '15 at 22:30
  • I tried this, and after the movie was done playing I got lots of errors similar to this: `GStreamer-CRITICAL **: Trying to dispose element inputselector0, but it is playing instead of the NULL state. You need to explixitly set elements to the NULL state before dropping the final reference, to allow them to clean up. This problem may also be caused by refcounting bug in the application or some element.` – John Jan 28 '16 at 23:55
2

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.

tumagonx
  • 71
  • 1
  • 3