Pipeline runs, but no display is shown
I am running this GStreamer C++ code on a Jetson ORIN but am not receiving a video feed. The pipeline works on command line but I am not sure what is going on with the code. Everything runs without error and the USB Camera (source) turns on and the light indicator shows that it is recording, but I don't see a display of the feed at all. The code before the the main are helper functions to integrate a termination sequence when either "q" or "Q" are entered or ctr+c is pressed.
Here is my code: It should run the loop for the received USB data and run until q/Q/ctr+C is entered. Right now it just says "Now Playing...\nRunning...\n" but does not open a video sink window.
#include
#include <gst/gst.h>
#include <glib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
/* v4l2src device=/dev/video0
! videoconvert
! video/x-raw,format=I420
! videoscale
! video/x-raw,width=640,height=480
! fpsdisplaysink text-overlay=true video-sink=autovideosink
*/
static gboolean running = TRUE;static void sigint_handler(int sig_num) { g_print("Terminating the application...\n"); running = FALSE; }gboolean keyboard_input(GIOChannel *source, GIOCondition condition, gpointer data) { gchar key; GError *error = NULL;
if (g_io_channel_read_chars(source, &key, 1, NULL, &error) == G_IO_STATUS_NORMAL) {
if (key == 'q' || key == 'Q') {
g_print("Terminating the pipeline...\n");
running = FALSE;
}
}
return TRUE;
}
Int main(int argc, char *argv[]) {
GMainLoop *loop = NULL; loop = g_main_loop_new(NULL, FALSE);
/* Initializing elements for pipeline */
GstElement *pipeline = NULL, *source = NULL, *converter = NULL,
*scaler = NULL, *sink = NULL;
/* Initialize GStreamer */
gst_init(&argc, &argv);
/* Create GStreamer pipeline */
pipeline = gst_pipeline_new("new-pipeline");
if (!pipeline) {
g_printerr("Failed to create the pipeline.\n");
return -1;
}
/* Create a source element (V4L2 source) */
source = gst_element_factory_make("v4l2src", "source");
if (!source) {
g_printerr("Failed to create v4l2src element.\n");
return -1;
}
g_object_set(G_OBJECT(source), "device", "/dev/video0", NULL);
gst_bin_add(GST_BIN(pipeline), source);
/* Create converter element */
converter = gst_element_factory_make("videoconvert", "converter");
if (!converter) {
g_printerr("Failed to create videoconvert element.\n");
return -1;
}
GstCaps *converter_caps = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "I420", NULL);
GstPad *srcpad = gst_element_get_static_pad(converter, "src");
if (!srcpad) {
g_printerr("Failed to get source pad for converter element.\n");
return -1;
}
gst_pad_set_caps(srcpad, converter_caps);
gst_object_unref(srcpad);
gst_bin_add(GST_BIN(pipeline), converter);
/* Create scaler element (videoscale) */
scaler = gst_element_factory_make("videoscale", "scaler");
if (!scaler) {
g_printerr("Failed to create videoscale element.\n");
return -1;
}
GstCaps *scaler_caps = gst_caps_new_simple("video/x-raw", "width", G_TYPE_INT, 640, "height", G_TYPE_INT, 480, NULL);
GstPad *sinkpad = gst_element_get_static_pad(scaler, "sink");
if (!sinkpad) {
g_printerr("Failed to get sink pad for scaler element.\n");
return -1;
}
gst_pad_set_caps(sinkpad, scaler_caps);
gst_object_unref(sinkpad);
gst_bin_add(GST_BIN(pipeline), scaler);
/* Create sink element (nvoverlaysink) */
sink = gst_element_factory_make("autovideosink", "video-output");
if (!sink) {
g_printerr("Failed to create nvoverlaysink element.\n");
return -1;
}
gst_bin_add(GST_BIN(pipeline), sink);
/* Set the pipeline to "playing" state */
g_print("Now playing:\n");
if (gst_element_set_state(pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
g_printerr("Failed to set the pipeline to the playing state.\n");
return -1;
}
/* Set up a signal handler for interrupt (Ctrl+C) */
signal(SIGINT, sigint_handler);
/* Set up a GIO channel to read keyboard input */
GIOChannel *io_channel = g_io_channel_unix_new(fileno(stdin));
g_io_add_watch(io_channel, G_IO_IN, keyboard_input, NULL);
/* Wait till pipeline encounters an error or EOS */
g_print("Running...\n");
while (running) {
g_main_context_iteration(NULL, TRUE);
}
/* Clean up resources */
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(pipeline);
g_main_loop_unref(loop);
g_io_channel_unref(io_channel);
return 0;
}