Traceback (most recent call last):
File "/home/ursaworks/vision/DeepStream-Yolo/test.py", line 113, in
fpsdisplaysink.set_property("video-sink", "nveglglessink")
TypeError: could not convert 'nveglglessink' to type 'GstElement' when setting property 'GstFPSDisplaySink.video-sink'
Assistant
The error message TypeError: could not convert 'nveglglessink' to type 'GstElement' when setting property 'GstFPSDisplaySink.video-sink' indicates that the video-sink property of fpsdisplaysink expects a GstElement object, not a string. You need to pass the actual nveglglessink element to the video-sink property.
Here's the corrected section of the code:
python
# Create fpsdisplaysink element
fpsdisplaysink = create_element("fpsdisplaysink", "fpsdisplaysink")
if not fpsdisplaysink:
exit()
# Set fpsdisplaysink properties
fpsdisplaysink.set_property("text-overlay", False)
fpsdisplaysink.set_property("video-sink", nveglglessink) # Pass the element itself
Explanation:
Instead of setting the video-sink property to the string "nveglglessink", we now set it to the nveglglessink element we created earlier using Gst.ElementFactory.make(). This provides the fpsdisplaysink element with the actual GStreamer element to use as its video sink.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Use GstPy: The script should use the standard GStreamer Python bindings (gi.repository.Gst). Include necessary imports like import gi; gi.require_version('Gst', '1.0'); from gi.repository import Gst, GLib.
Pipeline Structure: Create a Gst.Pipeline.
Element Creation: Instantiate each element using Gst.ElementFactory.make(). Handle potential None returns if an element factory is missing.
Property Setting: Set all specified properties for each element using element.set_property(). Pay close attention to:
The complex features string for aravissrc. Treat it as a single string property.
Numerical properties (width, height, batch-size, bitrate, max-size-time, max-size-buffers, GevSCPSPacketSize, AcquisitionFrameRate, Gain). Ensure correct data types (int, float, bool where applicable like GammaEnable).
Boolean properties derived from flags (compute-hw=1, live-source=1, text-overlay=false).
String properties (config-file-path, location, video-sink, muxer).
Enum-like properties (leaky, speed-preset, tune, format, stream-format, alignment, ExposureAuto, GainAuto, GammaSelector, OverlapMode). Use Gst introspection or common sense for potential enum values if direct string setting doesn't work (though often strings work for enums in GstPy).
Caps Filters: Create Gst.CapsFilter elements and set their caps property using Gst.Caps.from_string() for the specified capabilities (video/x-bayer,..., video/x-raw(memory:NVMM),..., video/x-h264,...).
Linking: Link the elements in the correct sequence using element.link().
Tee Handling: Correctly handle the tee element:
Get request pads from the tee (tee.get_request_pad('src_%u')).
Get static sink pads from the downstream elements (queue.get_static_pad('sink')).
Link the tee's source pads to the queue's sink pads.
NvStreamMux Handling: Correctly handle the nvstreammux element:
Get a request sink pad from the muxer (muxer.get_request_pad('sink_%u')).
Get the static source pad from the upstream element (queue.get_static_pad('src')).
Link the queue's source pad to the muxer's sink pad.
Main Loop: Include a GLib.MainLoop to run the pipeline asynchronously.
Bus Handling: Implement basic message handling on the pipeline's bus to listen for EOS (End-of-Stream) and ERROR messages, allowing the script to terminate gracefully. The -e flag in the original command implies EOS should be handled.
State Management: Set the pipeline state to PLAYING to start it and handle cleanup (setting state to NULL) upon exit.
Comments: Add comments to explain the different sections of the code (element creation, property setting, linking, main loop, etc.).
DeepStream Elements: Ensure all NVIDIA DeepStream elements (nvvidconv, nvstreammux, nvinfer, nvdsosd, nvegltransform, nveglglessink) are correctly instantiated and configured. Note that tcamconvert is likely from The Imaging Source, not NVIDIA, but should be handled similarly.
Please generate a complete, runnable Python script that replicates the functionality of the provided gst-launch-1.0 command.
python
import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GLib
# Initialize GStreamer
Gst.init(None)
# Create the pipeline
pipeline = Gst.Pipeline()
# Check if the pipeline was created successfully
if not pipeline:
print("ERROR: Could not create pipeline.")
exit()
# Function to create an element
def create_element(element_type, element_name):
element = Gst.ElementFactory.make(element_type, element_name)
if not element:
print(f"ERROR: Could not create element of type {element_type} named {element_name}. Check if the element is installed correctly.")
return None
return element
# Create aravissrc element
aravissrc = create_element("aravissrc", "aravis")
if not aravissrc:
exit()
# Set aravissrc properties
aravissrc.set_property("features", "OverlapMode=On Width=1024 Height=1024 ExposureAuto=Continuous AcquisitionFrameRate=88.5 AcquisitionFrameRateEnable=1 GevSCPSPacketSize=8164 Gain=0 GainAuto=Continuous GammaEnable=1 GammaSelector=sRGB")
# Create capsfilter for raw bayer video
capsfilter_bayer = create_element("capsfilter", "capsfilter_bayer")
if not capsfilter_bayer:
exit()
# Set capsfilter properties for bayer format
caps_bayer = Gst.Caps.from_string("video/x-bayer,width=1024,height=1024")
capsfilter_bayer.set_property("caps", caps_bayer)
# Create tcamconvert element
tcamconvert = create_element("tcamconvert", "tcamconvert")
if not tcamconvert:
exit()
# Create nvvidconv element (first instance)
nvvidconv1 = create_element("nvvidconv", "nvvidconv1")
if not nvvidconv1:
exit()
# Set nvvidconv properties (first instance)
nvvidconv1.set_property("compute-hw", True)
# Create capsfilter for NVMM NV12 video
capsfilter_nvmm = create_element("capsfilter", "capsfilter_nvmm")
if not capsfilter_nvmm:
exit()
# Set capsfilter properties for NVMM NV12 format
caps_nvmm = Gst.Caps.from_string("video/x-raw(memory:NVMM),format=NV12,width=640,height=640")
capsfilter_nvmm.set_property("caps", caps_nvmm)
# Create tee element
tee = create_element("tee", "t")
if not tee:
exit()
# Create queue elements (first branch)
queue1 = create_element("queue", "queue1")
if not queue1:
exit()
# Set queue properties (first branch)
queue1.set_property("max-size-buffers", 1)
queue1.set_property("leaky", "downstream") # Use string for enum
# Create nvstreammux element
nvstreammux = create_element("nvstreammux", "m")
if not nvstreammux:
exit()
# Set nvstreammux properties
nvstreammux.set_property("batch-size", 1)
nvstreammux.set_property("width", 640)
nvstreammux.set_property("height", 640)
nvstreammux.set_property("live-source", True)
# Create nvinfer element
nvinfer = create_element("nvinfer", "nvinfer")
if not nvinfer:
exit()
# Set nvinfer properties
nvinfer.set_property("config-file-path", "config_infer_primary_yoloV8.txt")
# Create nvdsosd element
nvdsosd = create_element("nvdsosd", "nvdsosd")
if not nvdsosd:
exit()
# Create nvegltransform element
nvegltransform = create_element("nvegltransform", "nvegltransform")
if not nvegltransform:
exit()
# Create fpsdisplaysink element
fpsdisplaysink = create_element("fpsdisplaysink", "fpsdisplaysink")
if not fpsdisplaysink:
exit()
# Set fpsdisplaysink properties
fpsdisplaysink.set_property("text-overlay", False)
fpsdisplaysink.set_property("video-sink", "nveglglessink")
# Create queue elements (second branch)
queue2 = create_element("queue", "queue2")
if not queue2:
exit()
# Set queue properties (second branch)
queue2.set_property("max-size-buffers", 1)
queue2.set_property("leaky", "downstream") # Use string for enum
# Create nvvidconv element (second instance)
nvvidconv2 = create_element("nvvidconv", "nvvidconv2")
if not nvvidconv2:
exit()
# Set nvvidconv properties (second instance)
nvvidconv2.set_property("compute-hw", True)
# Create x264enc element
x264enc = create_element("x264enc", "x264enc")
if not x264enc:
exit()
# Set x264enc properties
x264enc.set_property("bitrate", 10000)
x264enc.set_property("speed-preset", "ultrafast")
x264enc.set_property("tune", "zerolatency")
# Create capsfilter for h264 video
capsfilter_h264 = create_element("capsfilter", "capsfilter_h264")
if not capsfilter_h264:
exit()
# Set capsfilter properties for h264 format
caps_h264 = Gst.Caps.from_string("video/x-h264,stream-format=avc,alignment=au")
capsfilter_h264.set_property("caps", caps_h264)
# Create splitmuxsink element
splitmuxsink = create_element("splitmuxsink", "splitmuxsink")
if not splitmuxsink:
exit()
# Set splitmuxsink properties
splitmuxsink.set_property("location", "output_%05d.mp4")
splitmuxsink.set_property("max-size-time", 30000000000)
splitmuxsink.set_property("muxer", "mp4mux")
# Add elements to the pipeline
pipeline.add(aravissrc)
pipeline.add(capsfilter_bayer)
pipeline.add(tcamconvert)
pipeline.add(nvvidconv1)
pipeline.add(capsfilter_nvmm)
pipeline.add(tee)
pipeline.add(queue1)
pipeline.add(nvstreammux)
pipeline.add(nvinfer)
pipeline.add(nvdsosd)
pipeline.add(nvegltransform)
pipeline.add(fpsdisplaysink)
pipeline.add(queue2)
pipeline.add(nvvidconv2)
pipeline.add(x264enc)
pipeline.add(capsfilter_h264)
pipeline.add(splitmuxsink)
# Link elements
if not aravissrc.link(capsfilter_bayer):
print("ERROR: Could not link aravissrc and capsfilter_bayer.")
exit()
if not capsfilter_bayer.link(tcamconvert):
print("ERROR: Could not link capsfilter_bayer and tcamconvert.")
exit()
if not tcamconvert.link(nvvidconv1):
print("ERROR: Could not link tcamconvert and nvvidconv1.")
exit()
if not nvvidconv1.link(capsfilter_nvmm):
print("ERROR: Could not link nvvidconv1 and capsfilter_nvmm.")
exit()
if not capsfilter_nvmm.link(tee):
print("ERROR: Could not link capsfilter_nvmm and tee.")
exit()
# Link tee to queue1 (first branch)
tee_src_pad1 = tee.get_request_pad("src_%u")
queue1_sink_pad = queue1.get_static_pad("sink")
if tee_src_pad1 and queue1_sink_pad:
if tee_src_pad1.link(queue1_sink_pad) != Gst.PadLinkReturn.OK:
print("ERROR: Could not link tee and queue1.")
exit()
else:
print("ERROR: Could not get pads for linking tee and queue1.")
exit()
# Link queue1 to nvstreammux
queue1_src_pad = queue1.get_static_pad("src")
nvstreammux_sink_pad = nvstreammux.get_request_pad("sink_0")
if queue1_src_pad and nvstreammux_sink_pad:
if queue1_src_pad.link(nvstreammux_sink_pad) != Gst.PadLinkReturn.OK:
print("ERROR: Could not link queue1 and nvstreammux.")
exit()
else:
print("ERROR: Could not get pads for linking queue1 and nvstreammux.")
exit()
if not nvstreammux.link(nvinfer):
print("ERROR: Could not link nvstreammux and nvinfer.")
exit()
if not nvinfer.link(nvdsosd):
print("ERROR: Could not link nvinfer and nvdsosd.")
exit()
if not nvdsosd.link(nvegltransform):
print("ERROR: Could not link nvdsosd and nvegltransform.")
exit()
if not nvegltransform.link(fpsdisplaysink):
print("ERROR: Could not link nvegltransform and fpsdisplaysink.")
exit()
# Link tee to queue2 (second branch)
tee_src_pad2 = tee.get_request_pad("src_%u")
queue2_sink_pad = queue2.get_static_pad("sink")
if tee_src_pad2 and queue2_sink_pad:
if tee_src_pad2.link(queue2_sink_pad) != Gst.PadLinkReturn.OK:
print("ERROR: Could not link tee and queue2.")
exit()
else:
print("ERROR: Could not get pads for linking tee and queue2.")
exit()
if not queue2.link(nvvidconv2):
print("ERROR: Could not link queue2 and nvvidconv2.")
exit()
if not nvvidconv2.link(x264enc):
print("ERROR: Could not link nvvidconv2 and x264enc.")
exit()
if not x264enc.link(capsfilter_h264):
print("ERROR: Could not link x264enc and capsfilter_h264.")
exit()
if not capsfilter_h264.link(splitmuxsink):
print("ERROR: Could not link capsfilter_h264 and splitmuxsink.")
exit()
# Create a bus to check for errors
bus = pipeline.get_bus()
# Add signal watch to the bus
bus.add_signal_watch()
# Define a callback function to handle messages from the bus
def bus_call(bus, message, loop):
msg_type = message.type
if msg_type == Gst.MessageType.EOS:
print("End of stream")
loop.quit()
elif msg_type == Gst.MessageType.ERROR:
err, debug = message.parse_error()
print(f"Error: {err} ({debug})")
loop.quit()
return True
# Create a main loop
loop = GLib.MainLoop()
# Connect the bus to the main loop
bus.connect("message", bus_call, loop)
# Start playing the pipeline
pipeline.set_state(Gst.State.PLAYING)
try:
loop.run()
except:
pass
# Clean up
pipeline.set_state(Gst.State.NULL)