Encoding jpeg image after OSD causes segfault

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU) Jetson
• DeepStream Version 5
• JetPack Version (valid for Jetson only) 32.4
• Issue Type( questions, new requirements, bugs) Bug

Using deepstream-test5, I have added a pad probe to the sink pad of the instance sink_bin.

The probe function saves a jpeg image with the nvds_obj_enc API.

When OSD is disabled, this pad is connected to the demuxer. When OSD is disabled, it works correctly and saves images as desired.

When OSD is enabled, this pad is connected to the OSD bin. When OSD is enabled, I receive a segfault with the following message: 0x0000007fb759933c in jpegTegraEncoderCompress () from /usr/lib/aarch64-linux-gnu/tegra/libnvjpeg.so. The segfault occurs after executing nvds_obj_enc_finish.

I would like to save images after OSD so the image contains bounding boxes and the clock.

Any suggestion on how to proceed?

Can you provide the codes you modified?

The following code is at line 789 of deepstream_app.c:

  if (config->osd_config.enable) {
    NVGSTDS_ELEM_ADD_PROBE(instance_bin->all_bbox_buffer_probe_id,
                           instance_bin->osd_bin.nvosd, "sink",
                           gie_processing_done_buf_prob,
                           GST_PAD_PROBE_TYPE_BUFFER, instance_bin);
  } else {
    NVGSTDS_ELEM_ADD_PROBE(instance_bin->all_bbox_buffer_probe_id,
                           instance_bin->sink_bin.bin, "sink",
                           gie_processing_done_buf_prob,
                           GST_PAD_PROBE_TYPE_BUFFER, instance_bin);
  }
  if (config->image_save_config.enable) {
    NVGSTDS_ELEM_ADD_PROBE(appCtx->pipeline.img_save_buffer_probe_id, 
                           instance_bin->sink_bin.bin, "sink", 
                           img_save_buf_prob, 
                           GST_PAD_PROBE_TYPE_BUFFER, appCtx);
  }

I added the NVGSTDS_ELEM_ADD_PROBE at the end.

The probe function img_save_buf_prob is the same structure as the other buffer probes, and uses the same routine for saving images as in the deepstream-image-meta-test sample app.

The code works fine when OSD is disabled (set enabled=0), but I receive a segfault when OSD is enabled.

It is hard to know what happened without your complete codes. Can you upload all codes you have modified?

One thing to remind you is that nvds_obj_enc_process() needs NV12 surface input.

1 Like

My image saving code (probe function) is no different than in the example deepstream-image-meta-test.

I assume I need to use the NvBufSurfaceTransform API?

Do you know where I can find example code for using this library?

There are so many differences. The probe function is not in the same place as deepstream-image-meta-test. And I don’t know where did you put “nvds_obj_enc_create_context()”.

The deepstream-app is quite different to deepstream-image-meta-test. deepstream-image-meta-test is a fixed pipeline while deepstream-app pipeline will change according to the configuration.

Thank you for your response Fiona.Chen.

I am trying to save the image after OSD element. Would you recommend I use the NvBufSurfaceTransform or other API to have NV12 surface?

Thank you for your help with this.

When the OSD is enabled, the input format in “sink_bin.bin” sink pad is “RGBA”, when OSD is disabled, the input format in “sink_bin.bin” sink pad is “NV12”. Please make sure you have put the probe function in right place.

Yes, I believe the probe is in the right place, as the application does work properly (saves jpeg images) when OSD is disabled, but segfault when enabled.

Can you point me to some example code for how to convert RGBA to NV12?

Thank yoiu for your help.

You may need to add nvvideoconvert to do the job before “sink_bin.bin” when OSD is enabled.

I think I understand. Would you recommend this approach as opposed to operating on the individual buffers in my probe function?

Just to be clear, the nvvideoconvert element would link to the source pad of the OSD bin and convert RGBA to NV12, correct?

You want to use deepstream-app, so you need to change deepstream-app to adapt to your requirement. deepstream-image-meta-test has already shown you how to get the image from NvBufSurface.
If you think “sink_bin.bin” sink pad is the right place, the nvvideoconvert should be added after osd_bin and before sink_bin to convert the format.

Thank you @Fiona.Chen I will try that.

Can confirm, I am able to save images after OSD by using nvvideoconvert to make format NV12.

I ended up making a new fake sink bin and attaching the probe to the sink pad of the sink element, after nvvideoconvert element.

1 Like