大家好,我的问题与Nvidia Deepstream-5.0 SDK有关,
我正在尝试运行一个示例测试deepstream-nvdsanalytics-test,该测试位于NVIDIA Deepstream容器的"/source/apps/sample_apps"中。我想使用文件接收器保存视频文件。我得到的建议是研究create_encode_file_bin功能,该功能位于"/source/apps/apps-common/src/deepstream_sink_bin.c"。
我尝试更改代码deepstream_nvdsanalytics_test.cpp create_encode_file_bin作为参考,但遇到了一些错误。我正在发布我的管道,编辑的代码和错误,请看一下。
使用的管道-
PGE->NVtracker->nvdsanalytics->tiler->nvvidconv->nvosd->nvideoconvvert->caps filter(x/raw(->encoder->codecparse->mux->filesink
错误-
(deepstream-nvdsanalytics-test:203(: GStreamer-WARNING **: 16:08:13.115:名称"nvvideo转换器"在 bin 中不是唯一的 'nvdsanalytics-test-pipeline', 不添加
(deepstream-nvdsanalytics-test:203(: GStreamer-CRITICAL **: 16:08:13.116:gst_element_link_pads_full:断言GST_IS_ELEMENT (dest("失败的元素无法链接。退出。
法典-
#include <gst/gst.h> #include <glib.h> #include <stdio.h> #include <math.h> #include <string.h> #include <sys/time.h> #include <iostream> #include <vector> #include <unordered_map> #include "gstnvdsmeta.h" #include "nvds_analytics_meta.h" #include "deepstream_config.h" #ifndef PLATFORM_TEGRA #include "gst-nvmessage.h" #endif [....] int main (int argc, char *argv[]) { GMainLoop *loop = NULL; GstElement *pipeline = NULL, *streammux = NULL, *sink = NULL, *pgie = NULL, *nvtracker = NULL, *nvdsanalytics = NULL, *nvvidconv = NULL, *nvosd = NULL, *nvvidconv1 = NULL, *transform1 = NULL, *cap_filter = NULL, *encoder = NULL, *codecparse = NULL, *mux = NULL, *tiler = NULL; GstCaps *caps = NULL; #ifdef PLATFORM_TEGRA GstElement *transform = NULL; #endif GstBus *bus = NULL; guint bus_watch_id; GstPad *nvdsanalytics_src_pad = NULL; guint i, num_sources; guint tiler_rows, tiler_columns; guint pgie_batch_size; gulong bitrate = 2000000; guint profile = 0; /* Check input arguments */ if (argc < 2) { g_printerr ("Usage: %s <uri1> [uri2] ... [uriN] n", argv[0]); return -1; } num_sources = argc - 1; /* Standard GStreamer initialization */ gst_init (&argc, &argv); loop = g_main_loop_new (NULL, FALSE); /* Create gstreamer elements */ /* Create Pipeline element that will form a connection of other elements */ pipeline = gst_pipeline_new ("nvdsanalytics-test-pipeline"); /* Create nvstreammux instance to form batches from one or more sources. */ streammux = gst_element_factory_make ("nvstreammux", "stream-muxer"); if (!pipeline || !streammux) { g_printerr ("One element could not be created. Exiting.n"); return -1; } gst_bin_add (GST_BIN (pipeline), streammux); for (i = 0; i < num_sources; i++) { GstPad *sinkpad, *srcpad; gchar pad_name[16] = { }; GstElement *source_bin = create_source_bin (i, argv[i + 1]); if (!source_bin) { g_printerr ("Failed to create source bin. Exiting.n"); return -1; } gst_bin_add (GST_BIN (pipeline), source_bin); g_snprintf (pad_name, 15, "sink_%u", i); sinkpad = gst_element_get_request_pad (streammux, pad_name); if (!sinkpad) { g_printerr ("Streammux request sink pad failed. Exiting.n"); return -1; } srcpad = gst_element_get_static_pad (source_bin, "src"); if (!srcpad) { g_printerr ("Failed to get src pad of source bin. Exiting.n"); return -1; } if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK) { g_printerr ("Failed to link source bin to stream muxer. Exiting.n"); return -1; } gst_object_unref (srcpad); gst_object_unref (sinkpad); } /* Use nvinfer to infer on batched frame. */ pgie = gst_element_factory_make ("nvinfer", "primary-nvinference-engine"); /* Use nvtracker to track detections on batched frame. */ nvtracker = gst_element_factory_make ("nvtracker", "nvtracker"); /* Use nvdsanalytics to perform analytics on object */ nvdsanalytics = gst_element_factory_make ("nvdsanalytics", "nvdsanalytics"); /* Use nvtiler to composite the batched frames into a 2D tiled array based * on the source of the frames. */ tiler = gst_element_factory_make ("nvmultistreamtiler", "nvtiler"); /* Use convertor to convert from NV12 to RGBA as required by nvosd */ nvvidconv = gst_element_factory_make ("nvvideoconvert", "nvvideo-converter"); if (!nvvidconv) { g_printerr ("nvvdiconv element could not be created. Exiting.n"); } /* Create OSD to draw on the converted RGBA buffer */ nvosd = gst_element_factory_make ("nvdsosd", "nv-onscreendisplay"); if (!nvosd) { g_printerr ("nvosd element could not be created. Exiting.n"); } /* converter to convert RGBA to NV12 */ nvvidconv1 = gst_element_factory_make ("nvvideoconvert", "nvvideo-converter1"); if (!nvvidconv1) { g_printerr ("nvvidconv1 element could not be created. Exiting.n"); } /*create cap_filter */ cap_filter = gst_element_factory_make (NVDS_ELEM_CAPS_FILTER, "cap_filter"); if (!cap_filter) { g_printerr ("cap_filter element could not be created. Exiting.n"); } /* create cap for filter */ caps = gst_caps_from_string ("video/x-raw, format=I420"); g_object_set (G_OBJECT (cap_filter), "caps", caps, NULL); /* creatge encoder*/ encoder = gst_element_factory_make (NVDS_ELEM_ENC_H264_HW, "encoder"); if (!encoder) { g_printerr ("encoder element could not be created. Exiting.n"); } /* create transform1 */ transform1 = gst_element_factory_make (NVDS_ELEM_VIDEO_CONV, "transform1"); g_object_set (G_OBJECT (transform1), "gpu-id", 0, NULL); if (!transform1) { g_printerr ("transform1 element could not be created. Exiting.n"); } #ifdef IS_TEGRA g_object_set (G_OBJECT (encoder), "bufapi-version", 1, NULL); #endif g_object_set (G_OBJECT (encoder), "profile", profile, NULL); g_object_set (G_OBJECT (encoder), "bitrate", bitrate, NULL); /* create codecparse */ codecparse = gst_element_factory_make ("h264parse", "h264-parser"); if (!codecparse) { g_printerr ("codecparse element could not be created. Exiting.n"); } /* create mux */ mux = gst_element_factory_make (NVDS_ELEM_MUX_MP4, "mux"); if (!mux) { g_printerr ("mux element could not be created. Exiting.n"); } /* create sink */ sink = gst_element_factory_make (NVDS_ELEM_SINK_FILE, "filesink"); if (!sink) { g_printerr ("sink element could not be created. Exiting.n"); } g_object_set (G_OBJECT (sink), "location", "capture.mp4", "sync", 0, "async" , FALSE, NULL); // /* Finally render the osd output */ #ifdef PLATFORM_TEGRA transform = gst_element_factory_make ("nvegltransform", "nvegl-transform"); #endif // sink = gst_element_factory_make (NVDS_ELEM_SINK_FILE, "filesink"); // g_object_set (G_OBJECT (sink), "location", "capture.mp4", "sync", 0, "async" , FALSE, NULL); if (!pgie || !nvtracker || !nvdsanalytics || !nvvidconv || !nvosd || !nvvidconv1 || !cap_filter || !encoder || !codecparse || !mux || !sink) { g_printerr ("One element could not be created. Exiting.n"); return -1; } #ifdef PLATFORM_TEGRA if(!transform) { g_printerr ("One tegra element could not be created. Exiting.n"); return -1; } #endif g_object_set (G_OBJECT (streammux), "width", MUXER_OUTPUT_WIDTH, "height", MUXER_OUTPUT_HEIGHT, "batch-size", num_sources, "batched-push-timeout", MUXER_BATCH_TIMEOUT_USEC, NULL); /* Configure the nvinfer element using the nvinfer config file. */ g_object_set (G_OBJECT (pgie), "config-file-path", "nvdsanalytics_pgie_config.txt", NULL); /* Configure the nvtracker element for using the particular tracker algorithm. */ g_object_set (G_OBJECT (nvtracker), "ll-lib-file", "/opt/nvidia/deepstream/deepstream-5.0/lib/libnvds_nvdcf.so", "ll-config-file", "tracker_config.yml", "tracker-width", 640, "tracker-height", 480, NULL); /* Configure the nvdsanalytics element for using the particular analytics config file*/ g_object_set (G_OBJECT (nvdsanalytics), "config-file", "config_nvdsanalytics.txt", NULL); /* Override the batch-size set in the config file with the number of sources. */ g_object_get (G_OBJECT (pgie), "batch-size", &pgie_batch_size, NULL); if (pgie_batch_size != num_sources) { g_printerr ("WARNING: Overriding infer-config batch-size (%d) with number of sources (%d)n", pgie_batch_size, num_sources); g_object_set (G_OBJECT (pgie), "batch-size", num_sources, NULL); } tiler_rows = (guint) sqrt (num_sources); tiler_columns = (guint) ceil (1.0 * num_sources / tiler_rows); /* we set the tiler properties here */ g_object_set (G_OBJECT (tiler), "rows", tiler_rows, "columns", tiler_columns, "width", TILED_OUTPUT_WIDTH, "height", TILED_OUTPUT_HEIGHT, NULL); /* we add a message handler */ bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); bus_watch_id = gst_bus_add_watch (bus, bus_call, loop); gst_object_unref (bus); /* Set up the pipeline */ /* we add all elements into the pipeline */ #ifdef PLATFORM_TEGRA gst_bin_add_many (GST_BIN (pipeline), pgie, nvtracker, nvdsanalytics , nvvidconv, nvosd, nvvidconv1, cap_filter, encoder, codecparse, mux, sink, NULL); /* we link the elements together * nvstreammux -> nvinfer -> nvtracker -> nvdsanalytics -> nvtiler -> * nvvideoconvert -> nvosd -> transform -> sink */ if (!gst_element_link_many (streammux, pgie, nvtracker, nvdsanalytics, nvvidconv, nvosd, nvvidconv1, cap_filter, encoder, codecparse, mux, sink, NULL)) { g_printerr ("Elements could not be linked. Exiting.n"); return -1; } #else gst_bin_add_many (GST_BIN (pipeline), pgie, nvtracker, nvdsanalytics, nvvidconv, nvosd, nvvidconv1, cap_filter, encoder, codecparse, mux, sink, NULL); /* we link the elements together * nvstreammux -> nvinfer -> nvtracker -> nvdsanalytics -> nvtiler -> * nvvideoconvert -> nvosd -> sink */ if (!gst_element_link_many (streammux, pgie, nvtracker, nvdsanalytics, nvvidconv, nvosd, nvvidconv1, cap_filter, encoder, codecparse, mux, sink, NULL)) { g_printerr ("Elements could not be linked. Exiting.n"); return -1; } #endif /* Lets add probe to get informed of the meta data generated, we add probe to * the sink pad of the nvdsanalytics element, since by that time, the buffer * would have had got all the metadata. */ nvdsanalytics_src_pad = gst_element_get_static_pad (nvdsanalytics, "src"); if (!nvdsanalytics_src_pad) g_print ("Unable to get src padn"); else gst_pad_add_probe (nvdsanalytics_src_pad, GST_PAD_PROBE_TYPE_BUFFER, nvdsanalytics_src_pad_buffer_probe, NULL, NULL); /* Set the pipeline to "playing" state */ g_print ("Now playing:"); for (i = 0; i < num_sources; i++) { g_print (" %s,", argv[i + 1]); } g_print ("n"); gst_element_set_state (pipeline, GST_STATE_PLAYING); /* Wait till pipeline encounters an error or EOS */ g_print ("Running...n"); g_main_loop_run (loop); /* Out of the main loop, clean up nicely */ g_print ("Returned, stopping playbackn"); gst_element_set_state (pipeline, GST_STATE_NULL); g_print ("Deleting pipelinen"); gst_object_unref (GST_OBJECT (pipeline)); g_source_remove (bus_watch_id); g_main_loop_unref (loop); return 0; }
如果需要我提供任何其他信息,请告诉我。提前谢谢你。
按照以下 git diff 修改管道(注意:下面的 diff 适用于deepstream-test2
应用程序,它也可以在deepstream-nvdsanalytics-test
工作( 来源:
diff --git a/deepstream-test2/deepstream_test2_app.c b/deepstream-test2/deepstream_test2_app.c
index 2b1ff34..c31441e 100644
--- a/deepstream-test2/deepstream_test2_app.c
+++ b/deepstream-test2/deepstream_test2_app.c
@@ -318,6 +318,16 @@ main (int argc, char *argv[])
GstBus *bus = NULL;
guint bus_watch_id = 0;
GstPad *osd_sink_pad = NULL;
+
+ /* Added to save output to file */
+ GstElement *nvvidconv1 = NULL,
+ *filter1 = NULL, *filter2 = NULL,
+ *filter3 = NULL,
+ *videoconvert = NULL,
+ *filter4 = NULL,
+ *x264enc = NULL,
+ *qtmux = NULL;
+ GstCaps *caps1 = NULL, *caps2 = NULL, *caps3 = NULL, *caps4 = NULL;
/* Check input arguments */
if (argc != 2) {
@@ -373,17 +383,35 @@ main (int argc, char *argv[])
/* Create OSD to draw on the converted RGBA buffer */
nvosd = gst_element_factory_make ("nvdsosd", "nv-onscreendisplay");
+ /* Added to save output to file */
+ nvvidconv1 = gst_element_factory_make ("nvvideoconvert", "nvvideo-converter1");
+ videoconvert = gst_element_factory_make ("videoconvert", "converter");
+ x264enc = gst_element_factory_make ("x264enc", "h264 encoder");
+ qtmux = gst_element_factory_make ("qtmux", "muxer");
+
/* Finally render the osd output */
#ifdef PLATFORM_TEGRA
transform = gst_element_factory_make ("nvegltransform", "nvegl-transform");
#endif
- sink = gst_element_factory_make ("nveglglessink", "nvvideo-renderer");
+ sink = gst_element_factory_make ("filesink", "nvvideo-renderer");
+
+ /* caps filter for nvvidconv to convert NV12 to RGBA as nvosd expects input
+ * in RGBA format */
+ filter1 = gst_element_factory_make ("capsfilter", "filter1");
+ filter2 = gst_element_factory_make ("capsfilter", "filter2");
+ filter3 = gst_element_factory_make ("capsfilter", "filter3");
+ filter4 = gst_element_factory_make ("capsfilter", "filter4");
if (!source || !h264parser || !decoder || !pgie ||
!nvtracker || !sgie1 || !sgie2 || !sgie3 || !nvvidconv || !nvosd || !sink) {
g_printerr ("One element could not be created. Exiting.n");
return -1;
}
+ /* Added to test saving output to file */
+ if (!nvvidconv1 || !x264enc || !qtmux || !filter3 || !filter4) {
+ g_printerr ("One element could not be created. Exiting.n");
+ return -1;
+ }
#ifdef PLATFORM_TEGRA
if(!transform) {
@@ -395,6 +423,9 @@ main (int argc, char *argv[])
/* Set the input filename to the source element */
g_object_set (G_OBJECT (source), "location", argv[1], NULL);
+ /* Added to save output to file */
+ g_object_set (G_OBJECT (sink), "location", "out.mp4", NULL);
+
g_object_set (G_OBJECT (streammux), "batch-size", 1, NULL);
g_object_set (G_OBJECT (streammux), "width", MUXER_OUTPUT_WIDTH, "height",
@@ -429,9 +460,24 @@ main (int argc, char *argv[])
#else
gst_bin_add_many (GST_BIN (pipeline),
source, h264parser, decoder, streammux, pgie, nvtracker, sgie1, sgie2, sgie3,
- nvvidconv, nvosd, sink, NULL);
+ filter1, nvvidconv, filter2, nvosd, nvvidconv1, filter3, videoconvert, filter4,
+ x264enc, qtmux, sink, NULL);
#endif
+ /* Added to save output to file */
+ caps1 = gst_caps_from_string ("video/x-raw(memory:NVMM), format=NV12");
+ g_object_set (G_OBJECT (filter1), "caps", caps1, NULL);
+ gst_caps_unref (caps1);
+ caps2 = gst_caps_from_string ("video/x-raw(memory:NVMM), format=RGBA");
+ g_object_set (G_OBJECT (filter2), "caps", caps2, NULL);
+ gst_caps_unref (caps2);
+ caps3 = gst_caps_from_string ("video/x-raw, format=RGBA");
+ g_object_set (G_OBJECT (filter3), "caps", caps3, NULL);
+ gst_caps_unref (caps3);
+ caps4 = gst_caps_from_string ("video/x-raw, format=NV12");
+ g_object_set (G_OBJECT (filter4), "caps", caps4, NULL);
+ gst_caps_unref (caps4);
+
GstPad *sinkpad, *srcpad;
gchar pad_name_sink[16] = "sink_0";
gchar pad_name_src[16] = "src";
@@ -470,7 +516,8 @@ main (int argc, char *argv[])
}
#else
if (!gst_element_link_many (streammux, pgie, nvtracker, sgie1,
- sgie2, sgie3, nvvidconv, nvosd, sink, NULL)) {
+ sgie2, sgie3, filter1, nvvidconv, filter2, nvosd, nvvidconv1, filter3,
+ videoconvert, filter4, x264enc, qtmux, sink, NULL)) {
g_printerr ("Elements could not be linked. Exiting.n");
return -1;
}
对于deepstream-nvdsanalytics-test
,管道将是:
gst_bin_add_many (GST_BIN (pipeline), pgie, nvtracker, nvdsanalytics, tiler,
filter1, nvvidconv, filter2, nvosd, nvvidconv1, filter3, videoconvert, filter4,
x264enc, qtmux, sink, NULL);