Segfault when using nvarguscamerasrc to jpegenc pipeline

Just seen on Nx with devkit with:

$ cat /etc/nv_tegra_release 
# R32 (release), REVISION: 5.1, GCID: 27362550, BOARD: t186ref, EABI: aarch64, DATE: Wed May 19 18:16:00 UTC 2021

that the following pipeline (using RPi V2 IMX219 sensor) :

gst-launch-1.0 nvarguscamerasrc ! 'video/x-raw(memory:NVMM),format=NV12,width=3264,height=2464,framerate=21/1' ! nvvidconv ! 'video/x-raw,format=YUY2' ! jpegenc ! fakesink

results in segfault :

Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
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: 1640 x 1232 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: Running with following settings:
   Camera index = 0 
   Camera mode  = 0 
   Output Stream W = 3264 H = 2464 
   seconds to Run    = 0 
   Frame Rate = 21,000000 
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
^Chandling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 0:00:04.029921104
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
GST_ARGUS: Cleaning up
Caught SIGSEGV
#0  0x0000007f8826c310 in __GI___pthread_timedjoin_ex (threadid=547642130928, thread_return=0x0, abstime=0x0, block=<optimized out>)
#1  0x0000007f88327ab8 in  () at /usr/lib/aarch64-linux-gnu/libglib-2.0.so.0
#2  0x00000055954fa880 in  ()
Spinning.  Please run 'gdb gst-launch-1.0 14436' to continue debugging, Ctrl-C to quit, or Ctrl-\ to dump core.

(whatever is the format before jpegenc) when closing after a few seconds.

Using nvjpegedc works so far as workaround:

gst-launch-1.0 nvarguscamerasrc ! 'video/x-raw(memory:NVMM),format=NV12,width=3264,height=2464,framerate=21/1' ! nvvidconv ! 'video/x-raw(memory:NVMM),format=I420' ! nvjpegenc ! fakesink

Hi Honey Patouceul,
We can observe the segment fault. It looks specific to using nvarguscamerasrc, and happens in 3264x2464p21 sensor mode. Will do further investigation.

Hi Dane,
It also happens with 3264x1848p28 sensor mode.

Another case giving the same fault, this time using nvjpegenc after a copy into CPU memory, maybe the same cause. To be tested with the fix.

gst-launch-1.0 nvarguscamerasrc ! 'video/x-raw(memory:NVMM),format=NV12,width=3264,height=1848,framerate=28/1' ! nvvidconv ! video/x-raw,format=I420 ! nvvidconv ! 'video/x-raw(memory:NVMM),format=I420' ! nvjpegenc ! fakesink

Seems a workaround is just adding queue after nvarguscamerasrc:

gst-launch-1.0 nvarguscamerasrc ! 'video/x-raw(memory:NVMM),format=NV12,width=3264,height=1848,framerate=28/1' ! queue ! nvvidconv ! video/x-raw,format=I420 ! nvvidconv ! 'video/x-raw(memory:NVMM),format=I420' ! nvjpegenc ! fakesink

[EDIT: this workaround doesn’t work with EOS].

[EDIT2: Seems a workaround for nvjpegenc with EOS is rather using queue before nvjpegenc:

gst-launch-1.0 -ev nvarguscamerasrc ! 'video/x-raw(memory:NVMM),format=NV12,width=3264,height=1848,framerate=28/1' ! nvvidconv ! video/x-raw,format=I420 ! nvvidconv ! 'video/x-raw(memory:NVMM),format=I420' ! queue ! nvjpegenc ! fakesink

]

Hi Honey Patouceul,
This is fixed on Jetpack 4.6(r32.6.1). Please give it a try. Thanks.

Indeed, seems this bug no longer bites in R32.6 ;-)

BTW, why has sof-marker=4 been removed from SRC caps, while this is used in most cases ? (this is not specific to R32.6, older releases also have this unexpected behavior, where specifying sof-marker=4 in SRC caps lead to failure while this is exactly what the encoder will use).

Hi Honey Patouceul,
The code of nvjpegenc is based on v1.2.3 and the version does not have sof-marker=4. May manually add it if requiring the property.

Hi Dane,
I meant that nvjpegenc actually uses sof-marker 4, although its caps say this is not supported.
Obviously I can rebuild the plugin, but it looks weird that the plugin always uses a sof-marker that it says unsupported.