Segfault when `nvvideoconvert` and `nvv4l2h265enc` are used together

• Hardware Platform (Jetson / GPU): Jetson Nano
• DeepStream Version: 5.0.1
• JetPack Version (valid for Jetson only): 4.4
• TensorRT Version: N/A
• NVIDIA GPU Driver Version (valid for GPU only): N/A
• Issue Type( questions, new requirements, bugs): bug
• How to reproduce the issue ?: Described below
• Requirement details: N/A

Segmentation fault is caused when nvv4l2h265enc and nvvideoconvert are used together.
More specifically, in my observation, it is caused when the following conditions are met:

  • nvvideoconvert element is instantiated. (not necessarily added to a gstreamer pipeline)
  • nvv4l2h265enc (or nvv4l2h264enc) is running in a pipeline.

Details:

Code
import sys
import time
​
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst
​
​
def make_gst_element(factoryname, name=None, *, props=None):
    if name is None:
        name = factoryname
    element = Gst.ElementFactory.make(factoryname, name)
    if not element:
        raise RuntimeError(f"Unable to create streamer element: {factoryname}")
    if props:
        for key, value in props.items():
            element.set_property(key, value)
    return element
​
​
def main():
    GObject.threads_init()
    Gst.init(None)
​
    # Set True to cause segfault.
    bad = True
​
    # Create pipeline
    pipeline = Gst.Pipeline()
    if not pipeline:
        raise RuntimeError("Unable to create Pipeline")
​
    source = make_gst_element(
        "nvarguscamerasrc",
        props={
            'sensor-id': 0,
        })
​
    image_width = 816
    image_height = 616
    capsfilter = make_gst_element(
        "capsfilter",
        props={
            "caps": Gst.Caps.from_string(f"video/x-raw(memory:NVMM), width=(int){image_width}, height=(int){image_height}, format=(string)NV12, framerate=(fraction)21/1"),
        }
    )
    if bad:
        encoder = make_gst_element("nvv4l2h265enc")
    fakesink = make_gst_element("fakesink")
​
    # Only instantiated (not even added to the pipeline)
    make_gst_element("nvvideoconvert")
​
    # Add to pipeline
    pipeline.add(source)
    pipeline.add(capsfilter)
    pipeline.add(fakesink)
    if bad:
        pipeline.add(encoder)
​
    # Link
    source.link(capsfilter)
    if bad:
        capsfilter.link(encoder)
        encoder.link(fakesink)
    else:
        capsfilter.link(fakesink)
​
    # Start
    if pipeline.set_state(Gst.State.PLAYING) == Gst.StateChangeReturn.FAILURE:
        raise RuntimeError('Unable to start gstreamer pipeline')
​
    try:
        while True:
            time.sleep(10)
    finally:
        pipeline.set_state(Gst.State.NULL)
​
​
if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        sys.exit(1)
    except:
        import traceback
        traceback.print_exc()
        import pdb
        pdb.post_mortem()
Output
$ GST_DEBUG=3 python3 bad.py
Opening in BLOCKING MODE                                                                                                                                                                                 
0:00:00.116061984  3673     0x317dbb60 WARN                    v4l2 gstv4l2object.c:2372:gst_v4l2_object_add_interlace_mode:0x31777a40 Failed to determine interlace mode
0:00:00.116144485  3673     0x317dbb60 WARN                    v4l2 gstv4l2object.c:2372:gst_v4l2_object_add_interlace_mode:0x31777a40 Failed to determine interlace mode
0:00:00.116214069  3673     0x317dbb60 WARN                    v4l2 gstv4l2object.c:2372:gst_v4l2_object_add_interlace_mode:0x31777a40 Failed to determine interlace mode
0:00:00.116334019  3673     0x317dbb60 WARN                    v4l2 gstv4l2object.c:4430:gst_v4l2_object_probe_caps:<nvv4l2h265enc:src> Failed to probe pixel aspect ratio with VIDIOC_CROPCAP: Unknown err
or -1                                             
0:00:00.116905329  3673     0x314dc8a0 FIXME                default gstutils.c:3981:gst_pad_create_stream_id_internal:<nvarguscamerasrc:src> Creating random stream-id, consider implementing a determinist
ic way of creating a stream-id                                                                                                                         
NvMMLiteOpen : Block : BlockType = 8                                                                                                                  
===== NVMEDIA: NVENC =====                                                                                                                             
NvMMLiteBlockCreate : Block : BlockType = 8                                                                                                           
0:00:00.139390069  3673     0x314dc8a0 WARN          v4l2bufferpool gstv4l2bufferpool.c:1057:gst_v4l2_buffer_pool_start:<nvv4l2h265enc:pool:src> Uncertain or not enough buffers, enabling copy threshold
GST_ARGUS: Creating output stream                   
CONSUMER: Waiting until producer is connected...                                                                                                      
GST_ARGUS: Available Sensor modes :     
GST_ARGUS: 3264 x 2464 FR = 21.000000 fps Duration = 47619048 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
                                                 
GST_ARGUS: 3264 x 1848 FR = 28.000001 fps Duration = 35714284 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
                                                               
GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
                                             
GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
                                         
GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
                                                                           
GST_ARGUS: Running with following settings:
   Camera index = 0
   Camera mode  = 4
   Output Stream W = 1280 H = 720
   seconds to Run    = 0
   Frame Rate = 120.000005
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
Segmentation fault (core dumped)
Output (gdb)
(gdb) cont
Continuing.
[New Thread 0x7fb40631f0 (LWP 7260)]
[New Thread 0x7fb38621f0 (LWP 7261)]
[New Thread 0x7fb30611f0 (LWP 7262)]
[New Thread 0x7fb28601f0 (LWP 7263)]
[New Thread 0x7fafd741f0 (LWP 7264)]
Opening in BLOCKING MODE
0:00:00.652504935  6775       0xde3760 WARN                    v4l2 gstv4l2object.c:2372:gst_v4l2_object_add_interlace_mode:0xd7ed00 Failed to determine interlace mode
0:00:00.652594988  6775       0xde3760 WARN                    v4l2 gstv4l2object.c:2372:gst_v4l2_object_add_interlace_mode:0xd7ed00 Failed to determine interlace mode
0:00:00.652647020  6775       0xde3760 WARN                    v4l2 gstv4l2object.c:2372:gst_v4l2_object_add_interlace_mode:0xd7ed00 Failed to determine interlace mode
0:00:00.652744782  6775       0xde3760 WARN                    v4l2 gstv4l2object.c:4430:gst_v4l2_object_probe_caps:<nvv4l2h265enc:src> Failed to probe pixel aspect ratio with VIDIOC_CROPCAP: Unknown error -1
[New Thread 0x7faf3ac1f0 (LWP 7265)]
0:00:00.653799692  6775       0xae34a0 FIXME                default gstutils.c:3981:gst_pad_create_stream_id_internal:<nvarguscamerasrc:src> Creating random stream-id, consider implementing a deterministic way of creating a stream-id
[New Thread 0x7faebab1f0 (LWP 7266)]
[New Thread 0x7fae3aa1f0 (LWP 7267)]
NvMMLiteOpen : Block : BlockType = 8
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 8
[New Thread 0x7fadba91f0 (LWP 7269)]
0:00:00.677425387  6775       0xae34a0 WARN          v4l2bufferpool gstv4l2bufferpool.c:1057:gst_v4l2_buffer_pool_start:<nvv4l2h265enc:pool:src> Uncertain or not enough buffers, enabling copy threshold
GST_ARGUS: Creating output stream
[New Thread 0x7f8ffff1f0 (LWP 7409)]
[New Thread 0x7f8f7fe1f0 (LWP 7410)]
[New Thread 0x7f8effd1f0 (LWP 7411)]
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 3264 x 2464 FR = 21.000000 fps Duration = 47619048 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 3264 x 1848 FR = 28.000001 fps Duration = 35714284 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: Running with following settings:
   Camera index = 0
   Camera mode  = 4
   Output Stream W = 1280 H = 720
   seconds to Run    = 0
   Frame Rate = 120.000005
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
[New Thread 0x7f8e7fc1f0 (LWP 7414)]

Thread 7 "nvarguscamerasr" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7faf3ac1f0 (LWP 7265)]
0x0000007fb0a5f170 in ?? () from /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvvideo4linux2.so
(gdb) bt
#0  0x0000007fb0a5f170 in  () at /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvvideo4linux2.so
#1  0x0000007fb0a63458 in  () at /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvvideo4linux2.so
#2  0x0000007fb0a7700c in  () at /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvvideo4linux2.so
#3  0x0000007fb68ae774 in  () at /usr/lib/aarch64-linux-gnu/libgstvideo-1.0.so.0
#4  0x0000000000b18e00 in  ()

nvvideoconvert and nvv4l2h265enc can work together.

The problem may be caused by nvarguscamerasrc. If you want to use nvarguscamerasrc and nvvideoconvert together, you need to set the property “bufapi-version” to true for nvarguscamerasrc.

1 Like

Thank you for a quick reply, that did the trick!

But what does the property mean?
I can’t find any documentation.

use “gst-inspect-1.0 nvarguscamerasrc” command to check the properties, there is some simple explanation.

1 Like

Thank you!