Reputation: 423
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
.
Upvotes: 2
Views: 733
Reputation: 371
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.
Upvotes: 1
Reputation: 7373
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.
Upvotes: 0