2013-10-30 139 views
1

我嘗試使用C API來顯示此圖像當我嘗試它,它做工精細我用這個GST-launch命令顯示圖像

gst-launch filesrc location="pluto.jpg" ! jpegdec ! ffmpegcolorspace ! videobalance saturation=0 ! freeze ! ximagesink 

做GStreamer的管道,但是當我嘗試將其轉換爲C代碼它不起作用有人可以幫助我嗎?

#include <gst/gst.h> 

int main(int argc, char *argv[]) { 
    GstElement *pipeline, *jpdec, *imgf, *cod, *source, *sink; 
    GstBus *bus; 
    GstMessage *msg; 
    GstStateChangeReturn ret; 

    /* Initialize GStreamer */ 
    gst_init (&argc, &argv); 

    /* Create the elements */ 
    source = gst_element_factory_make ("filesrc", "source"); 
    sink = gst_element_factory_make ("ximagesink", "sink"); 
jpdec = gst_element_factory_make ("jpegdec", "jdec"); 
imgf = gst_element_factory_make ("imagefreeze", "freeze"); 
cod = gst_element_factory_make ("ffmpegcolorspace", "ffmdec"); 

    /* Create the empty pipeline */ 
    pipeline = gst_pipeline_new ("test-pipeline"); 

    if (!pipeline || !source || !sink || !jpdec || !imgf || !cod) { 
    g_printerr ("Not all elements could be created.\n"); 
    return -1; 
    } 

    /* Build the pipeline */ 
    gst_bin_add_many (GST_BIN (pipeline), source, jpdec, cod, imgf, sink, NULL); 
    if (gst_element_link (source, sink) != TRUE) { 
    g_printerr ("Elements could not be linked.\n"); 
    gst_object_unref (pipeline); 
    return -1; 
    } 

    /* Modify the source's properties */ 
    g_object_set (G_OBJECT (source), "location","pluto.jpg", NULL); 

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

存在,我使用當我編譯代碼我沒有錯誤,玩圖像
但是當我運行它,我有這個ERREUR C代碼:

(test:5355): GStreamer-CRITICAL **: gst_caps_get_structure: assertion `GST_IS_CAPS (caps)' failed 

(test:5355): GStreamer-CRITICAL **: gst_structure_get_int: assertion `structure != NULL' failed 
Error received from element sink: Failed to create output image buffer of 0x0 pixels 
Debugging information: ximagesink.c(472): gst_ximagesink_ximage_new(): /GstPipeline:test-pipeline/GstXImageSink:sink: 
could not get shared memory of 0 bytes 
+0

那些看起來不像編譯時錯誤。你確定他們不是運行時錯誤嗎? (你知道有什麼區別嗎?) – abelenky

+0

不,我不知道你能解釋的區別嗎? – user2936743

+0

第1步是***編譯***你的程序,將其從源代碼改爲計算機代碼。編譯期間可能會出錯。在程序編譯成功後,第2步是運行***程序以實際執行計算機代碼。在運行時您可能會遇到一組不同的錯誤。當你編譯***你的程序,或者當你運行你的程序時,你是否得到這些錯誤? – abelenky

回答

1

你gst_element_link是錯的。例如:

if (gst_element_link_many (source, jpdec, cod, imgf, sink, NULL) != TRUE) 

應該工作。

這些錯誤可能是xvimagesink中的錯誤,但您錯誤地使用了它。如果發生1.0錯誤,請隨時向bugzilla.gnome.org報告這些錯誤。