Hi!
I’m trying to create a RSTP server using the Gstreamer Gst Python library in the Jetson Xavier, Jetpack 5.0.1-b118 and Gstreamer 1.16
The server works fine using as h264 encoder the x264enc (in the code, making h264_cpu = True):
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import Gst, GLib, GstRtspServer
class VideoServerRTSP:
def __init__(self, h264_cpu):
self.loop = self._generate_gst_rtsp_server(h264_cpu)
self.loop.run()
def _generate_gst_rtsp_server(self, h264_cpu):
Gst.init(None)
if h264_cpu:
pipeline = f"v4l2src device=/dev/video0 " \
f"! videorate ! videoscale " \
f"! video/x-raw,width=640,height=480,framerate=30/1 " \
f"! videoconvert ! video/x-raw,format=I420 " \
f"! x264enc " \
f"! rtph264pay name=pay0 pt=96"
else:
pipeline = f"v4l2src device=/dev/video0 " \
f"! videorate ! videoscale " \
f"! video/x-raw,width=640,height=480,framerate=30/1 " \
f"! videoconvert " \
f"! video/x-raw,format=I420 " \
f"! nvvidconv " \
f"! 'video/x-raw(memory:NVMM), format=(string)I420' " \
f"! nvv4l2h264enc insert-sps-pps=1 idrinterval=15 " \
f"! rtph264pay name=pay0 pt=96 --gst-debug=4"
server = GstRtspServer.RTSPServer.new()
server.set_service(str('5050'))
mounts = server.get_mount_points()
factory = GstRtspServer.RTSPMediaFactory.new()
factory.set_launch(pipeline)
factory.set_shared(True)
mounts.add_factory('/test', factory)
server.attach()
loop = GLib.MainLoop()
return loop
if __name__ == '__main__':
h264_cpu = True
server = VideoServerRTSP(h264_cpu)
However, when trying to use the nvv4l2h264enc encoder, the code throws the following error:
(python3.8:14554): GStreamer-CRITICAL **: 15:55:45.663: gst_element_make_from_uri: assertion ‘gst_uri_is_valid (uri)’ failed
(python3.8:14554): GStreamer-CRITICAL **: 15:55:45.705: gst_element_link_pads_filtered: assertion ‘GST_IS_BIN (parent)’ failed
(python3.8:14554): GStreamer-CRITICAL **: 15:55:45.713: gst_element_link_pads_filtered: assertion ‘GST_IS_BIN (parent)’ failed
Opening in BLOCKING MODE
The funny thing is that using the that same piece of pipeline for streaming the video over UDP:
gst-launch-1.0 v4l2src device=/dev/video0 ! videorate ! videoscale ! video/x-raw,width=640,height=480,framerate=30/1 ! videoconvert ! video/x-raw,format=I420 ! nvvidconv ! 'video/x-raw(memory:NVMM), format=(string)I420' ! nvv4l2h264enc insert-sps-pps=1 preset-level=1 ! rtph264pay name=pay0 pt=96 ! udpsink host=127.0.0.1 port=1234
works perfectly.
Any ideas about what is going on?
Thanks in advance!