user3769141
user3769141

Reputation: 13

Gstreamer Elements not linking

I am new to Gstreamer and I have a question about why my elements will not link together. Here is my code:

CustomData data;

data.videosource = gst_element_factory_make("uridecodebin", "source");
cout << "Created source element " << data.videosource << endl;
data.demuxer = gst_element_factory_make("qtdemux", "demuxer");
cout << "Created demux element " << data.demuxer << endl;
data.decoder = gst_element_factory_make("ffdec_h264", "video-decoder");
cout << "Went to the video path " << data.decoder << endl;          
data.videoconvert = gst_element_factory_make("ffmpegcolorspace", "convert"); 
cout << "Created convert element " << data.videoconvert << endl;
data.videosink = gst_element_factory_make("autovideosink", "sink");
cout << "Created sink element " << data.videosink << endl;

if (!data.videosource ||!data.demuxer || !data.decoder || !data.videoconvert || !data.videosink)
{
    g_printerr ("Not all elements could be created.\n");
    system("PAUSE");
    return;
}

//Creating the pipeline
data.pipeline = gst_pipeline_new("video-pipeline");
if (!data.pipeline)
{
    g_printerr ("Pipeline could not be created.");
}


//Setting up the object
g_object_set(data.videosource, "uri", videoFileName[camID] , NULL);
//videoFileName[camID] is a char** with the content uri=file:///C://videofiles/...mp4


//Adding elements to the pipeline
gst_bin_add_many(GST_BIN (data.pipeline), data.videosource, data.demuxer, data.decoder, data.videoconvert, data.videosink, NULL);
//This is where the issue occurs
   if(!gst_element_link(data.videosource, data.demuxer)){
        g_printerr("Elements could not be linked. \n");
        system("PAUSE");
        return;
}

What I am trying to do is to break down a mp4 file and display only the video content but for some reason when I try to link source and demuxer, it comes out as false.

Thank you guys so much!

Upvotes: 1

Views: 6024

Answers (1)

mreithub
mreithub

Reputation: 1222

Let's have a look at the pipeline you're using (I'll use gst-launch here for its brevity, but the same goes for any GStreamer pipelines):

gst-launch uridecodebin uri=file:///path/to/movie.avi \
   ! qtdemux ! ffdec_h264 ! ffmpegcolorspace \
   ! autovideosink

gst-inspect uridecodebin states:
Autoplug and decode an URI to raw media

So uridecodebin takes any audio/video source and decodes it by internally using some of GStreamer's other elements.
Its output is something like video/x-raw-rgb or audio/x-raw-int (raw audio/video)

qtdemux on the other hand takes a QuickTime stream (still encoded) and demuxes it.

But what it gets in your example is the already decoded raw video (which is why it won't link).

So, you've basically got two options:

  • just use uridecodebin

    gst-launch uridecodebin uri=file:///path/to/movie.avi \
       ! autovideosink
    

    which will allow your pipeline to decode pretty much any video file

  • just use the qtdemux ! ffdec_h264 ! ffmpegcolorspace elements:

    gst-launch filesrc=/path/to/movie.avi \
       ! qtdemux ! ffdec_h264 ! ffmpegcolorspace
       ! autovideosink
    

Keep in mind however that your pipeline doesn't play audio.
To get that as well do one of the following:

  • Simply use playbin2

    gst-launch playbin2 uri=file:///path/to/movie.avi
    
  • Connect your decodebin to an audio sink as well gst-launch uridecodebin name=d uri=... ! autovideosink d. ! autoaudiosink

Upvotes: 5

Related Questions