[gst-devel] Get width and height from video

Kirill Kirichenko kirill.kirichenko at gmail.com
Fri Jul 18 13:39:03 CEST 2008


Probably you're getting audio pad first.
You should extract width/height info whenever there is a video pad.
Check the structure name in newpad function. It should contain either
"video" or "image" string.


On Fri, Jul 18, 2008 at 3:20 PM, AlannY <alanny at starlink.ru> wrote:
> I'm writting small program which extracts width and height from video file.
>
> After creating a pipeline, I'm adding *filesrc* element and *decodebin*
> elements. On *decodebin*, I'm attaching handler to the *new-decoded-pad*
> callback. Then add it to the pipeline, link and play (with help of
> g_main_loop_run). The source attached.
>
> In the handler of *new-decoded-pad* signal, I'm getting caps from pad,
> then GstStructure of that caps. From structure, I want to extract width
> and height. After then, I'm exiting from g_mail_loop and program.
>
> But there are error: every time, I got 0 (zero) for width and height.
>
> I suppose, that I'm doing something totally wrong ;-( Can some one
> explain me my mistake?
>
> *** SOURCE ***
>
> #include <gst/gst.h>
>
> GMainLoop *loop;
>
> static void
> newpad (GstElement *decodebin,
>           GstPad     *pad,
>           gboolean    last,
>           gpointer    data)
> {
>   GstCaps *caps;
>   GstStructure *str;
>
>   /* Get caps from pad */
>   caps = gst_pad_get_caps (pad);
>   /* Get structure */
>   str = gst_caps_get_structure (caps, 0);
>
>   /* Get height */
>   gint height = 0;
>   gst_structure_get_int (str, "height", &height);
>
>   g_print ("%d\n", height);
>
>   gst_caps_unref (caps);
>
>   g_main_loop_quit (loop);
> }
>
> gint
> main (gint   argc,
>       gchar *argv[])
> {
>   GstElement *pipeline, *src, *dec;
>
>   gst_init (&argc, &argv);
>   loop = g_main_loop_new (NULL, FALSE);
>
>   if (argc != 2) {
>     g_print ("Usage: %s <filename>\n", argv[0]);
>     return -1;
>   }
>
>   /* Pipeline */
>   pipeline = gst_pipeline_new ("pipeline");
>
>   /* Source (file) */
>   src = gst_element_factory_make ("filesrc", "source");
>   g_object_set (G_OBJECT (src), "location", argv[1], NULL);
>
>   /* Decodebin */
>   dec = gst_element_factory_make ("decodebin", "decoder");
>   g_signal_connect (dec, "new-decoded-pad", G_CALLBACK (newpad), NULL);
>
>   /* Add and Link */
>   gst_bin_add_many (GST_BIN (pipeline), src, dec, NULL);
>   gst_element_link_many (src, dec, NULL);
>
>   /* Play */
>   gst_element_set_state (pipeline, GST_STATE_PLAYING);
>   g_main_loop_run (loop);
>
>   /* Free */
>   gst_element_set_state (pipeline, GST_STATE_NULL);
>   gst_object_unref (GST_OBJECT (pipeline));
>
>   return 0;
> }
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
>




More information about the gstreamer-devel mailing list