Frames acquired from NvBufSurface from one source gets mixed with frames of other sources

• Hardware Platform (Jetson / GPU)
• DeepStream Version
• NVIDIA GPU Driver Version (valid for GPU only)


I am trying to use opencv to save/cache frames from a certain source and save them as a video if some condition occurs. I have followed this code snippet Deepstream sample code snippet - #3 by bcao. I have also followed the gst-dsexample plugin.

The issue is that the video I save is filled with frames from all the sources and not just the source I specified.

The following is the code I added to the bbox_generated_probe_after_analytics callback function in test5 app.

Note that I don’t want to transform the buffer surface (do not want to crop or filter the images) and that I am setting memory types as cuda unified memory.

    GstMapInfo in_map_info;
    NvBufSurface *surface;
    NvDsFrameMetaList * l_frame;
    NvDsFrameMeta *frame_meta;

    memset(&in_map_info, 0, sizeof(in_map_info));
    if (!gst_buffer_map (buf, &in_map_info, GST_MAP_READ)) {
        g_print ("Error: Failed to map gst buffer\n");
        goto error;

    surface = (NvBufSurface *);

    for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;
        l_frame = l_frame->next) {
        frame_meta = (NvDsFrameMeta *) (l_frame->data);
        NvBufSurfaceMap (surface, -1, -1, NVBUF_MAP_READ);
        /* Cache the mapped data for CPU access */
        NvBufSurfaceSyncForCpu (surface, 0, 0); // will do nothing for unified memory type on dGPU
        guint height = surface->surfaceList[frame_meta->batch_id].height;
        guint width = surface->surfaceList[frame_meta->batch_id].width;

        cv::Mat nv12_mat = cv::Mat(height*3/2, width, CV_8UC1, 
        cv::Mat bgr_frame;
        cv::cvtColor (nv12_mat, bgr_frame, cv::COLOR_YUV2BGR_NV12);

        // saving from source 0 just for testing 
        if (frame_meta->batch_id == 0) {
                // -----------------------------
                // push back frame to the frames vector
                // if certain condition occurred, save last x frames as a video with opencv video writer
                // -----------------------------

This is an attempted workaround to the memory leak issue of the smart-recording feature (Memory leak in test5-app with smart-record) which has not been resolved yet.

Please reply ASAP.
Thank you.

Never mind, I was just using frame_meta->source_id and frame_meta->batch_id interchangeably which was causing the issue. It’s now solved.

Glad to know issue resolved!

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