Segmentation fault when extracting the frame using a probe

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU) GPU
• DeepStream Version 6.2
**• Language ** Python

I get a segmentation fault error when extracting frames from a multi-stream input pipeline using a probe. Complete code to reproduce this issue is attached herewith (refer test.py)

probe code is as follows :

def osd_sink_pad_buffer_probe(pad, info, u_data):
   
    gst_buffer = info.get_buffer()
    if not gst_buffer: 
        print("Unable to get GstBuffer ")
        return

    batch_meta = pyds.gst_buffer_get_nvds_batch_meta(hash(gst_buffer))
    if not batch_meta:
        return Gst.PadProbeReturn.OK

    l_frame = batch_meta.frame_meta_list

    while l_frame is not None:
        print("iterating frames..............")
        
        try:
            frame_meta = pyds.NvDsFrameMeta.cast(l_frame.data)
        except StopIteration:
            continue

        l_obj = frame_meta.obj_meta_list
        n_frame = pyds.get_nvds_buf_surface(hash(gst_buffer), frame_meta.batch_id)
        frame_copy = np.array(n_frame, copy=True, order='C')
        frame_copy  = cv2.cvtColor(frame_copy, cv2.COLOR_RGBA2BGR)

        while l_obj is not None:
            try:
                obj_meta = pyds.NvDsObjectMeta.cast(l_obj.data)
            except StopIteration:
                continue
        
            pass

            try:
                l_obj = l_obj.next
            except StopIteration:
                break

        try:
            l_frame = l_frame.next
        except StopIteration:
            break

    return Gst.PadProbeReturn.OK

pipeline code is as follows :

Gst.init(None)
pipeline = Gst.Pipeline()

video_list = ['file:///workdir/test.h264',
                    'file:///workdir/test.h264']

streammux = Gst.ElementFactory.make("nvstreammux", "Stream-muxer")

streammux.set_property("batched-push-timeout", 25000)
streammux.set_property("batch-size", 30)
streammux.set_property("gpu_id", GPU_ID)

pipeline.add(streammux)
streammux.set_property("live-source", 1)   # need to check

for  id, uri in enumerate(video_list):
    print("Creating source_bin ",uri," \n ")

    #Create first source bin and add to pipeline
    source_bin= create_uridecode_bin((id, uri))
    if not source_bin:
        sys.stderr.write("Failed to create source bin. Exiting. \n")
        sys.exit(1)

    pipeline.add(source_bin)

pgie = Gst.ElementFactory.make("nvinfer", "primary-inference")

nvvidconv = Gst.ElementFactory.make("nvvideoconvert", "convertor")

nvosd = Gst.ElementFactory.make("nvdsosd", "onscreendisplay")

sink = Gst.ElementFactory.make("fakesink", "fakesink")


streammux.set_property('width', 1920)
streammux.set_property('height', 1080)
pgie.set_property('config-file-path', "model_config.txt")
pgie.set_property("gpu_id", GPU_ID)
pgie.set_property("batch-size",MAX_SOURCE)


nvvidconv.set_property("gpu_id", GPU_ID)
nvosd.set_property("gpu_id", GPU_ID)

print("Adding elements to Pipeline \n")
pipeline.add(pgie)
pipeline.add(nvvidconv)
pipeline.add(nvosd)
pipeline.add(sink)


print("Linking elements in the Pipeline \n")
streammux.link(pgie)
pgie.link(nvvidconv)
nvvidconv.link(nvosd)
nvosd.link(sink)

the problem is with frame extraction I assume

        n_frame = pyds.get_nvds_buf_surface(hash(gst_buffer), frame_meta.batch_id)
        frame_copy = np.array(n_frame, copy=True, order='C')
        frame_copy  = cv2.cvtColor(frame_copy, cv2.COLOR_RGBA2BGR)

test.py (5.8 KB)

Also, can you tell me the most efficient way to extract frames from a multistream input pipeline, with demux plugin or without it?

Can you share the config file and stream cause crash ?

Use your code with dstest1_pgie_config.txt here

and use sample stream

/opt/nvidia/deepstream/deepstream/samples/streams/sample_720p.h264

It’s can run success.

i am still getting segmentation faults with the config and video URL shared by @junshengy , I think the way I extract frames using a probe is not right

Can you check the driver/cuda/trt version ?

nvidia-smi for driver version
nvcc -V for cuda version
dpkg -l | grep nvinfer for trt version

Can you try this sample first ?
This version is recommended

the versions are as follows

Driver Version: 525.105.17 CUDA Version: 12.0
Cuda compilation tools, release 11.5, V11.5.119
Build cuda_11.5.r11.5/compiler.30672275_0

the sample code worked fine

I know where the problem is .You can upgrade the cuda version.

1.Add caps filter after nvvidconv before nvosd,like this.

caps = Gst.Caps.from_string("video/x-raw(memory:NVMM), format=RGBA")
filter = Gst.ElementFactory.make("capsfilter", "filter")
if not filter:
    sys.stderr.write(" Unable to get the caps filter1 \n")
filter.set_property("caps", caps)

modify color format to

frame_copy = cv2.cvtColor(frame_copy, cv2.COLOR_RGBA2BGRA)

2.Use cuda unified memory

if not is_aarch64():
    # Use CUDA unified memory in the pipeline so frames
    # can be easily accessed on CPU in Python.
    mem_type = int(pyds.NVBUF_MEM_CUDA_UNIFIED)
    streammux.set_property("nvbuf-memory-type", mem_type)
    nvvidconv.set_property("nvbuf-memory-type", mem_type)

Please refer to the sample code.

Thanks

1 Like

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