微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何通过我自己的 gstreamer 管道从 Jetson Nano CSI 摄像机录制视频?

如何解决如何通过我自己的 gstreamer 管道从 Jetson Nano CSI 摄像机录制视频?

我跑:

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

和 gst-launch 将来自 Jetson Nano 的 CSI 摄像机的视频记录到文件中。但是我需要用 C++ 编写自己的 Pipeline,它将执行相同的任务。我做了以下事情:

#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,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",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",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,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,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;
}

我编译这段代码

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

运行:

sudo ./dsdwcamcap 

并得到这个错误

(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 683709000;

GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000,max 683709000;

GST_ARGUS: 1640 x 1232 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000,max 683709000;

GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000,max 683709000;

GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000,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)

我无法弄清楚错误是什么。我是 gstreamer 的新手,所以可能是一些小错误。如果您能提供帮助,我将不胜感激。

UPD:我应该在 EOS 上插入一个循环和检查。您可以在此处阅读所有相关信息 https://gstreamer.freedesktop.org/documentation/application-development/basics/helloworld.html?gi-language=c 。 EOS 检查在 bus_call 函数中。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。