gst-launch pipeline vs its exact C analog

Martijn Grendelman martijn at iphion.nl
Wed Mar 28 03:48:55 PDT 2012


On 28-03-12 11:13, Sergei Vorobyov wrote:
> Hi!
> 
> Your help will be greatly appreciated.
> 
> I am struggling to understand and wondering why
> 
> gst-launch filesrc location=file.avi ! decodebin2 ! ffmpegcolorspace !
> autovideosink
> 
> works just fine as expected, whereas its straightforward C-programmed analog
> 
>   src = gst_element_factory_make ("filesrc", "source");
>   g_object_set (src, "location", "file.avi", NULL);
> 
>   dec = gst_element_factory_make ("decodebin2", "decoder"); // won't
> link to the next
>   conv = gst_element_factory_make ("ffmpegcolorspace", "ffmpeg-colorspace");
>   sink = gst_element_factory_make ("autovideosink", "sink");
> 
>   gst_bin_add_many (GST_BIN (pipeline),
> 		    src,
> 		    dec,
> 		    conv,
> 		    sink, NULL);
> 
>   if (!gst_element_link (src, dec)) {
>     g_print("cannot link src and dec\n");
>     return -1;
>   }
> 
>   if (!gst_element_link (dec, conv)) { // FAILS here
>     g_print("cannot link dec and conv\n");
>     return -1;
>   }
> 
> reports "cannot link dec and conv", i.e., gst_element_link (dec, conv) FAILS.
> 
> If I take away return -1, allowing it to proceed, it results in:
> 
> Error from element avidemux0: Internal data stream error.
> Debug: gstavidemux.c(5204): gst_avi_demux_loop ():
> /GstPipeline:length/GstDecodeBin2:decoder/GstAviDemux:avidemux0:
> streaming stopped, reason not-linked

Decodebin2's source pads are dynamic, meaning they will only be added when
appropriate. I don't know when exactly that is, but it is at least after
the demuxer/decoder have determined what kind of media types are present
in the input.

You have to catch its "pad-added" signals and link the pads from there.

> caught in the callback for the loop/pipeline
> 
> 
>     if (msg_type & GST_MESSAGE_ERROR) {
>       g_print ("ERROR message\n");
>       gchar *debug;
>       GError *err;
> 
>       gst_message_parse_error (msg, &err, &debug);
>       g_free (debug);
> 
>       g_print ("Error from element %s: %s\n",
> 	       GST_OBJECT_NAME (msg->src),
> 	       err->message);
>       g_print ("Debug: %s\n", (debug) ? debug : "none");
>       g_error_free (err);
>       g_free (debug);
> 
>       g_main_loop_quit (loop);
>     }

Best regards,
Martijn Grendelman


More information about the gstreamer-devel mailing list