Minimal example of streaming RTSP video from USB camera with a custom overlay in Jetson Nano with RTSP in Python3.7+


I’m currently working on a Python 3.7+ application that runs in Jetson Nano and performs the following actions:

  • Consumes video from a USB web camera, for example a Logitech C270.
  • Adds an overlay to the original camera image (for example a text with a counter).
  • Publishes RTSP to be consumed from other devices: an android application, VLC, etc.

An example of using GStreamer is provided in this topic. This solution requires installing python bindings for GStreamer, but Jetpack does not have native support for Python 3.7 and PyGObject Python 3.7 can be installed but then it fails to import gi.

Code migrated to Python 3:

import gi


from gi.repository import GObject, Gst, GstVideo, GstRtspServer

mainloop = GObject.MainLoop()

server = GstRtspServer.RTSPServer()
mounts = server.get_mount_points()
factory = GstRtspServer.RTSPMediaFactory()

factory.set_launch('( videotestsrc is-live=1 ! video/x-raw,width=320,height=240,framerate=30/1 ! nvvidconv ! nvv4l2h264enc insert-sps-pps=1 idrinterval=30 insert-vui=1 ! rtph264pay name=pay0 pt=96 )')

mounts.add_factory("/test", factory)
print("stream ready at rtsp://")

Error when running:

Traceback (most recent call last):
  File "", line 1, in <module>
    import gi
  File "/usr/lib/python3/dist-packages/gi/", line 42, in <module>
    from . import _gi
ImportError: cannot import name '_gi' from 'gi' (/usr/lib/python3/dist-packages/gi/

Thanks in advance,


This would need other users to share experience. The default python3 in Jetpack 4 releases is 3.6.9. Please also try the version and see if the failure is specific to 3.7.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.