2014-06-24 57 views
0

我是Gstreamer的新手,我有一個關於爲什麼我的元素不會鏈接在一起的問題。這裏是我的代碼:Gstreamer元素沒有鏈接

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; 
} 

我所試圖做的是要打破一個MP4文件,並只顯示視頻內容,但由於某種原因,當我試圖鏈接源和分流器,它出來是假的。

謝謝你們這麼多!

回答

3

讓我們來看看你正在使用的管道(我會在這裏使用gst-launch以其簡潔,但同樣適用於任何GStreamer的管道):

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

gst-inspect uridecodebin狀態:
Autoplug並將URI解碼爲原始媒體

因此,uridecodebin可以採用任何音頻/視頻源,並通過內部使用某些GStreamer的其他元素進行解碼。
它的輸出是在另一方面像video/x-raw-rgbaudio/x-raw-int(原始音頻/視頻)

qtdemux需要一個QuickTime流(仍然編碼),解複用器它。

但是它在你的例子中得到的是已經解碼的原始視頻(這就是爲什麼它不會鏈接)。

所以,你基本上有兩個選擇:

  • 只使用uridecodebin

    ,這將使您的管道解碼幾乎任何視頻文件

  • 只是使用qtdemux ! ffdec_h264 ! ffmpegcolorspace元素:

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

請記住,您的管道不能播放音頻。
要獲得以及執行下列操作之一:

  • 只需使用playbin2

    gst-launch playbin2 uri=file:///path/to/movie.avi 
    
  • decodebin到音頻接收器以及 GST推出連接uridecodebin名= d URI =。 ..! autovideosink d。 ! autoaudiosink
+0

非常感謝你的回答。我從中學到了很多! – user3769141