@elyaabbas9 We have quite a bit of experience developing custom plugins on GstPython using DeepStream.
DeepStream
On DeepStream version 5.0 the python bindings are included with the DeepStream SDK installation. However, you still need to install the bindings for GStreamer and GObject and then run the install script in DeepStream:
cd /opt/nvidia/deepstream/deepstream-5.0/lib
sudo python3 setup.py install
For more information check the Python bindings API reference another excellent source is the deepstream_python_apps repo.
GStreamer
The GStreamer python bindings can be installed with apt:
sudo apt install python-gi-dev python-gst-1.0 gstreamer1.0-python3-plugin-loader
The plugin support in GStreamer is not stable in GStreamer 1.14.5. There is no documentation for creating elements, but your best bet is to check the examples in the GitHub repo. These bindings only provide structures to map GStreamer buffers and other elements in python, some of the functionalities and the support to create plugins. Most of the GStreamer objects and their methods are defined in the GObject bindings.
GObject
The documentation for the GStreamer modules of the GObject python bindings is available here. The API is similar to GStreamer on C, but some of the functionalities are missing.
Know Issues
These issues are specific to GStreamer 1.14 and I know for a fact that they are fixed on 1.16:
- Can’t map the input buffer for writting
- Installing multiple properties causes a segfault
I can provide you our workarounds for these issues if you are interested
Example
Finally here is an empty example plugin:
import gi
import os
import platform
import sys
gi.require_version('Gst', '1.0')
gi.require_version('GstBase', '1.0')
gi.require_version('GstVideo', '1.0')
gi.require_version('GLib', '2.0')
def is_aarch64():
return platform.uname()[4] == 'aarch64'
sys.path.append('/opt/nvidia/deepstream/deepstream-5.0/sources/python/bindings/' +
('jetson' if is_aarch64() else 'x86_64'))
from gi.repository import Gst, GObject, GLib, GstBase, GstVideo
Gst.init(None)
FIXED_CAPS = Gst.Caps.from_string(
'video/x-raw,format={ (string)RGBA, (string)I420 },width=[1,2147483647],height=[1,2147483647],framerate=[ 0/1, 2147483647/1 ]')
FIXED_CAPS.append(Gst.Caps.from_string(
'video/x-raw(memory:NVMM),format={ (string)RGBA, (string)NV12 },width=[1,2147483647],height=[1,2147483647],framerate=[ 0/1, 2147483647/1 ]'))
class GstPycustom(GstBase.BaseTransform):
__gstmetadata__ = (
'PyCustom',
'Generic',
'Custom python element',
'Miguel Taylor <miguel.taylor@ridgerun.com>')
__gsttemplates__ = (
Gst.PadTemplate.new(
"src",
Gst.PadDirection.SRC,
Gst.PadPresence.ALWAYS,
FIXED_CAPS),
Gst.PadTemplate.new(
"sink",
Gst.PadDirection.SINK,
Gst.PadPresence.ALWAYS,
FIXED_CAPS))
__gproperties__ = {}
def __init__(self):
GstBase.BaseTransform.__init__(self)
GstBase.BaseTransform.set_in_place(self, True)
def do_transform_ip(self, buf):
Gst.debug("transform_ip")
#custom operation
return Gst.FlowReturn.OK
GObject.type_register(GstPycustom)
__gstelementfactory__ = ("pycustom", Gst.Rank.NONE, GstPycustom)
To install python plugins simply copy the source into /usr/lib/aarch64-linux-gnu/gstreamer-1.0/python/
or any other path in GST_PLUGIN_PATH
. The sources must to be inside a folder named python
and the element name must coincide with the file name, for example for pycustom
the file name should be gstpycustom.py
I hope this is enough information to get you started.