How can i get jpeg data from the plugin nvjpegenc?

I creat a deepstream pipeline as follow:
gst-launch-1.0 uridecodebin uri=file:///opt/nvidia/deepstream/deepstream-5.0/samples/streams/sample_720p.mp4 ! nvvideoconvert ! ‘video/x-raw(memory:NVMM),format=NV12,width=640,height=360’ ! m.sink_0 nvstreammux name=m batch-size=1 width=640 height=480 ! nvvideoconvert ! nvdsosd ! nvvideoconvert ! video/x-raw, format=I420 ! nvjpegenc ! appsink

It can work correctly. The appsink’s sample function source code as fowed. I can get the NvDsBatchMeta data correctly, but my question is how can i get the jpeg data?

static GstFlowReturn
new_sample (GstElement * sink, gpointer * data)
{
GstSample *sample;
GstBuffer *buf = NULL;
guint num_rects = 0;
NvDsObjectMeta *obj_meta = NULL;
guint vehicle_count = 0;
guint person_count = 0;
NvDsMetaList *l_frame = NULL;
NvDsMetaList *l_obj = NULL;
unsigned long int pts = 0;
GstMapInfo map;

sample = gst_app_sink_pull_sample (GST_APP_SINK (sink));
if (gst_app_sink_is_eos (GST_APP_SINK (sink))) 
{
	g_print ("EOS received in Appsink********\n");
}
g_print ("\n\r just for a test\n\r ");
//gst_sample_unref (sample);
//return GST_FLOW_OK;
if (sample) 
{
	/* Obtain GstBuffer from sample and then extract metadata from it. */
	buf = gst_sample_get_buffer (sample);
	gst_buffer_map (buf, &map, GST_MAP_READ);

	g_print ("\n\r map.size =%d \n\r ", map.size);
	gst_buffer_unmap(buf, &map);
	
	NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta (buf);

	for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;l_frame = l_frame->next)
	{
		NvDsFrameMeta *frame_meta = (NvDsFrameMeta *) (l_frame->data);
		pts = frame_meta->buf_pts;
		
		for (l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next)
		{
			obj_meta = (NvDsObjectMeta *) (l_obj->data);
			if (obj_meta->class_id == PGIE_CLASS_ID_VEHICLE) 
			{
				vehicle_count++;
				num_rects++;
			}
			if (obj_meta->class_id == PGIE_CLASS_ID_PERSON) 
			{
				person_count++;
				num_rects++;
			}
		}
	}

	g_print ("	111 Frame Number = %d Number of objects = %d "
			"Vehicle Count = %d Person Count = %d PTS = %" GST_TIME_FORMAT "\n",
			frame_number, num_rects, vehicle_count, person_count,
			GST_TIME_ARGS (pts));
	frame_number++;
	gst_sample_unref (sample);
	return GST_FLOW_OK;
}
return GST_FLOW_ERROR;

}

Hi,
Please refer to

map.data is the pointer to compressed jpeg image.

1 Like

As the doc, i get the jpeg data , but the size is not correct. My be the it effect by the nvds batch meta, i wan know the map of the jpeg data and the nvds batch mata. My be i refer to the function “nvds_obj_enc_process”, but i not fond the source code of this function.

Hi,
nvds_obj_enc_process is to encode detected objects. What you get in appsink is the whole frame compressed to jpeg.

1 Like

yes, i wan get the jpeg data length , so i can copy it to another buffer and send it to the ethernet。 how can i get the jpeg data length? i can copy it one by one byte until meet the hex 0xff 0xd9 , but it is low efficiency.

yes, i wan get the jpeg data length , so i can copy it to another buffer and send it to the ethernet。 how can i get the jpeg data length? i can copy it one by one byte until meet the hex 0xff 0xd9 , but it is low efficiency.

Hi,
map.size should give the jpeg data length from 0xFFD8 to 0xFFD9.

1 Like

Thank you for your replay , i get the right jpeg data.