How do I record video from the Jetson Nano CSI camera through my own gstreamer pipeline?

Please provide complete information as applicable to your setup.

**• Hardware Platform Jetson Nano
**• DeepStream Version 5.1
**• JetPack Version 4.5.1
**• TensorRT Version 7.1.3

I run:

gst-launch-1.0 -e nvarguscamerasrc sensor_id=0 num-buffers=300 ! "video/x-raw(memory:NVMM), width=(int)3246, height=(int)2464, format=(string)NV12, framerate=(fraction)21/1" ! nvvidconv flip-method=2 ! "video/x-raw(memory:NVMM), format=(string)NV12" ! omxh264enc ! qtmux ! filesink location=full_size.mkv

and gst-launch records video to a file from the Jetson Nano’s CSI camera. But I need to write my own Pipeline in C++, which will perform the same task. I did the following:

#include <gst/gst.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>




int main(int argc, char *argv[]) {

        GstElement *pipeline, *source, *capsfilter_one, *nvvidconv, *capsfilter_two, *omxh264enc, *qtmux, *filesink, *sink, *fakesink;
        GstStateChangeReturn ret;

        /* Initialize GStreamer */
        gst_init (&argc, &argv);

        source = gst_element_factory_make("nvarguscamerasrc", "source");
        capsfilter_one = gst_element_factory_make("capsfilter", "input-capsfilter");
        nvvidconv = gst_element_factory_make("nvvidconv", "nvvidconv");
        capsfilter_two = gst_element_factory_make("capsfilter", "osd-capsfilter");
        omxh264enc = gst_element_factory_make("omxh264enc", "omxh264enc");
        qtmux = gst_element_factory_make("qtmux", "qtmux");
        filesink = gst_element_factory_make("filesink", "filesink");

        pipeline = gst_pipeline_new ("dsdewarper-from-camera");

        if (!pipeline || !source || !capsfilter_one  || !nvvidconv || !capsfilter_two || !omxh264enc || !qtmux || !filesink) {
                g_printerr ("Not all elements could be created.\n");
                return -1;
        }

        /* Build the pipeline */
        gst_bin_add_many (GST_BIN (pipeline), source, capsfilter_one, nvvidconv, capsfilter_two, omxh264enc, qtmux, filesink, NULL);
        if (!gst_element_link_many (source, capsfilter_one, nvvidconv, capsfilter_two, omxh264enc, qtmux, filesink, NULL)) {
                g_printerr("Elements could not be linked.\n");
                gst_object_unref(pipeline);
                return -1;
        }

        /* Modify the source's properties */
        g_object_set(source, "sensor-id", 0, NULL);
        g_object_set(source, "num-buffers", 300, NULL);
        g_object_set(nvvidconv, "flip-method", 2, NULL);
        g_object_set(filesink, "location", "cameracap.mkv", NULL);

        GstCaps* const capsfilter_one_caps
        {
                gst_caps_new_simple("video/x-raw",
                                "width", G_TYPE_INT, 3264,
                                "height", G_TYPE_INT, 2464,
                                "framerate", GST_TYPE_FRACTION, 21, 1,
                                nullptr)
        };
        GstCapsFeatures* const memory_features { gst_caps_features_new("memory:NVMM", nullptr) };
        gst_caps_set_features(capsfilter_one_caps, 0, memory_features);
        g_object_set(capsfilter_one, "caps", capsfilter_one_caps, nullptr);
        GstCaps* const capsfilter_two_caps { gst_caps_from_string("video/x-raw(memory:NVMM), format=(string)NV12") };
        g_object_set(capsfilter_two, "caps", capsfilter_two_caps, nullptr);


        /* Start playing */
        ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
        if (ret == GST_STATE_CHANGE_FAILURE) {
                g_printerr ("Unable to set the pipeline to the playing state.\n");
                gst_object_unref (pipeline);
                return -1;
        }


        /* Free resources */
        gst_element_set_state (pipeline, GST_STATE_NULL);
        gst_object_unref (pipeline);
        return 0;
}

I compile this code:

sudo gcc dsdwcamcap.cpp -o dsdwcamcap `pkg-config --cflags --libs gstreamer-1.0`

run:

sudo ./dsdwcamcap 

and get this error:

(dsdwcamcap:12071): GStreamer-CRITICAL **: 19:19:39.577: gst_mini_object_set_qdata: assertion 'object != NULL' failed
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: 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  = 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.
GST_ARGUS: Cleaning up
nvbuf_utils: dmabuf_fd -1 mapped entry NOT found
nvbuf_utils: Can not get HW buffer from FD... Exiting...
CONSUMER: Done Success
GST_ARGUS: Done Success
WARNING Argus: 2 client objects still exist during shutdown:
    545527958304 (0x7f74001d18)
    547502957504 (0x7f7c001880)

I can’t figure out what the mistake is. I am new to gstreamer, so probably some trivial error. I will be grateful if you can help.

I can’t find g_main_loop() in your code. Please refer to gstreamer document and sample code. Your first application (gstreamer.freedesktop.org)

This is not gsreamer forum. Please post your questions and issues for gstreamer in gstreamer maillist. GStreamer: Mailing Lists

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