Elements could not be linked when build pipeline using gstreamer
I tried debugging tool gst-launch-1.0 with this pipeline: gst-launch-1.0 -e rtspsrc location=rtsp://192.168.50.53/stream1 ! rtph264depay ! h264parse ! mp4mux ! filesink location=test.mp4. I run this in the terminal well. But when I turn it into a C program, I can not run the executable. And through my debugging info, I guess this pipeline have problems when elements linked together. I have tried to remove the mp4mux element in the pipeline, since pad type not compatible. But it still not working. I attached my code, and hope anyone can give me some advice. Thanks in advance!!!
Env info: windows system using tut code in Visual Studio, ONLY replacing the code in basic-tutorial-1.c file and build "basic-tutorial-1" project. Then I get basic-tutorial-1.exe in "gst-docs-master\examples\tutorials\vs2010\x64\Debug" directory.
code is here:
` #include <gst/gst.h>
int main(int argc, char *argv[]) { g_print ("Main process begin.\n"); GstElement *pipeline, *source, *sink, *depay, *parse, *mp4mux; GstBus *bus; GstMessage *msg; GstStateChangeReturn ret; g_print ("Start init.\n");
/* Initialize GStreamer */
gst_init (&argc, &argv);
g_print ("Init finish.\n");
/* Create the elements */
source = gst_element_factory_make("rtspsrc", "source");
g_printerr("rtspsrc finish.\n");
depay = gst_element_factory_make("rtph264depay", "depay");
g_printerr("rtph265depay finish.\n");
parse = gst_element_factory_make("h264parse", "parse");
g_printerr("h265parse finish.\n");
mp4mux = gst_element_factory_make("mp4mux", "mp4mux");
g_printerr("mp4mux finish.\n");
sink = gst_element_factory_make("filesink", "sink");
g_printerr("Create elements finish.\n");
/* Create the empty pipeline */
pipeline = gst_pipeline_new("rtsp-pipeline");
g_printerr("Create pipeline finish.\n");
if (!pipeline || !source || !sink || !depay || !parse || !mp4mux) {
g_printerr("!ERROR!! Not all elements could be created.\n");
return -1;
}
/* Build the pipeline */
gst_bin_add_many(GST_BIN(pipeline), source, depay, parse, sink, NULL);
g_printerr("Elements bind finish.\n");
if (gst_element_link_many(source, depay, parse, sink) != TRUE) {
g_printerr("!ERROR!! Elements could not be linked.\n");
gst_object_unref(pipeline);
return -1;
}
g_printerr("Elements linked finish.\n");
/* Modify the properties of source and sink */
g_object_set(G_OBJECT(source), "location", "rtsp://192.168.50.53/stream1", NULL);
g_object_set(G_OBJECT(sink), "location", "D:/bellaliu/test.mp4", NULL);
g_printerr("Source and sink properties set.\n");
/* 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;
}
/* Wait until error or EOS */
bus = gst_element_get_bus(pipeline);
msg =
gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE,
GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
/* Parse message */
if (msg != NULL) {
GError *err;
gchar *debug_info;
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_ERROR:
gst_message_parse_error(msg, &err, &debug_info);
g_printerr("Error received from element %s: %s\n",
GST_OBJECT_NAME(msg->src), err->message);
g_printerr("Debugging information: %s\n",
debug_info ? debug_info : "none");
g_clear_error(&err);
g_free(debug_info);
break;
case GST_MESSAGE_EOS:
g_print("End-Of-Stream reached.\n");
break;
default:
/* We should not reach here because we only asked for ERRORs and EOS */
g_printerr("Unexpected message received.\n");
break;
}
gst_message_unref(msg);
}
/* Free resources */
gst_object_unref(bus);
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(pipeline);
return 0;
} `