2

I am trying to use Gstreamer with python bindings in order to search for available cameras on my system. As a result I would like to obtain a list of devices with their corresponding capabilities (width, height, framerate...).

Gstreamer offers very useful class called Gst.DeviceMonitor to obtain available devices. However, I ran into problems when tying to extract capabilities from the discovered devices. Concretely, I only have troubles with obtaining capabilities "pixel-aspect-ratio" and "framerate", which are both of Gst.Fraction type.

Here is a minimal code example:

import gi

gi.require_version('Gst', '1.0')
from gi.repository import Gst

Gst.init(None)

caps = Gst.Caps.from_string('video/x-h264,width=640,height=480,framerate={30/1, 20/1, 15/1, 1/1}')
structure = caps.get_structure(0)

width = structure.get_int('width').value
height = structure.get_int('height').value
framerates = structure.get_list('framerate').array

print('width = ', width)
print('height = ', height)
for i in range(framerates.n_values):
    print(' - framerate = ', framerates.get_nth(i))

The following exception is thrown on the last line:

TypeError: unknown type GstFraction

I have found here that someone had similar issue in 2012, but I have not found any solutions. Does anybody have any suggestion?

PS: I am using Python 3.5.5 and Gstreamer 1.14.5.

Matej Jeglič
  • 403
  • 3
  • 11

2 Answers2

1

I had exactly the same problem and I finally found the solution: Install the package python3-gst-1.0:

sudo apt install python3-gst-1.0

I'm surprised everything else worked without that package.

danmou
  • 321
  • 2
  • 4
0

Your code runs just fine on Ubuntu 18:

$ python3 --version
Python 3.6.9

$ gst-inspect-1.0 --version
gst-inspect-1.0 version 1.14.5

width =  640
height =  480
 - framerate =  30/1
 - framerate =  20/1
 - framerate =  15/1
 - framerate =  1/1

So it may be a bug in the Python GStreamer/GObject introspection bindings.

Florian Zwoch
  • 6,764
  • 2
  • 12
  • 21
  • I have updated Python to 3.8.6. I run the example code before and I still get the same error. I have also tried with Python 3.6.9 (just like you) and again the result is the same. The only difference is that I am using Ubuntu 20. Do you have any other advise what might be different? – Matej Jeglič Oct 19 '20 at 07:56