Why the video not play when I link decodebin with xvimagsink?

Tim-Philipp Müller t.i.m at zen.co.uk
Sun Jun 9 03:51:57 PDT 2013


On Sat, 2013-06-08 at 20:17 -0700, DBOYaoao wrote:

Hi,

> 
>     I use decodebin2 's dynmic pad  to link with xvimagesink,but the video
> not play,I only see the first frame of file!

First of all: do you know about playbin2 (in 0.10) or playbin (in 1.0) ?

It will take care of all of this stuff for you. You can still set
specific audio/video sinks if you like.

If you only see the first frame, that sounds like the pipeline never
actually goes into PLAYING state. Maybe the audio sink didn't link?
(could be a missing audioconvert ! audioresample) Does it work if you
replace alsasink with a fakesink ?

Cheers
 -Tim

> This is the code:
>     void cb_newpad (GstElement* decodebin,GstPad* pad,gpointer user_data)
> {
>     printf("add new pad\n");
>     GstPad *audiopad;
>     GstPad *videopad;
>     GstCaps *caps;
>     GstStructure *str;
> 
>     audiopad = gst_element_get_static_pad (audiosink, "sink");
>     if (GST_PAD_IS_LINKED (audiopad)) {
>         printf("audio has linked\n");
>     g_object_unref (audiopad);
>     return;
>     }
>     videopad = gst_element_get_static_pad (videosink, "sink");
>     if (GST_PAD_IS_LINKED (videopad)) {
>          printf("video has linked\n");
>     g_object_unref (videopad);
>     return;
>     }
>     //caps = gst_pad_query_caps(pad, NULL);
>     //
> 
>     caps = gst_pad_get_caps(pad);
>     str = gst_caps_get_structure (caps, 0);
>     if (g_strrstr (gst_structure_get_name (str), "audio")) {
>         gst_caps_unref (caps);
> 
>         if(gst_pad_link (pad, audiopad) != 0)
>         {
>             printf("link video error\n");
>         }
>         gst_object_unref (audiopad);
> 
>     }
>     else if(g_strrstr (gst_structure_get_name (str), "video"))
>     {
>         gst_caps_unref (caps);
> 
>         if(gst_pad_link(pad,videopad) !=0)
>         {
>             printf("link video error\n");
>         }
>         gst_object_unref (videopad);
>     }
> 
> #if 0
>     gst_caps_unref (caps);
>     gst_object_unref (audiopad);
>     return;
>     gst_caps_unref (caps);
> #endif
> 
> }
> 
> 
> 
> int main(int argc,char **argv)
> {
>     gst_init(&argc,&argv);
>     loop = g_main_loop_new(NULL, FALSE);
>     pipeline = gst_pipeline_new ("video-player");
>     src = gst_element_factory_make("filesrc", "file-source");
>     decode = gst_element_factory_make("decodebin2", "video-dec");
>     g_signal_connect (decode, "pad-added", G_CALLBACK (cb_newpad), NULL);
>     videosink = gst_element_factory_make("xvimagesink", "video-output");
>     audiosink = gst_element_factory_make("alsasink","audio-output");
>     bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
>     bus_watch_id = gst_bus_add_watch (bus, bus_call, loop);
>     gst_object_unref (bus);
>     if (!pipeline || !src || !decode || !videosink || !audiosink ) {
>         g_printerr ("One element could not be created. Exiting.\n");
>         return -1;
>     }
> 
>     g_object_set (G_OBJECT (src), "location", argv[1], NULL);
> 
>     gst_bin_add_many (GST_BIN (pipeline),src, decode, videosink,audiosink,
> NULL);
>     if(!gst_element_link (src, decode))
>     {
>         printf("link src and decode error\n");
>         return 0;
>     }
>    // gst_element_link_many (src,decode,NULL);
> 
> 
>     gst_element_set_state (pipeline, GST_STATE_PLAYING);
>     g_print ("Running...\n");
>     g_main_loop_run (loop);
> 
>     return 0;
> }
> 
> Thanks for your help!!
> 
> 
> 
> --
> View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Why-the-video-not-play-when-I-link-decodebin-with-xvimagsink-tp4660445.html
> Sent from the GStreamer-devel mailing list archive at Nabble.com.
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel




More information about the gstreamer-devel mailing list