[gst-devel] Get width and height from video

AlannY alanny at starlink.ru
Fri Jul 18 13:20:23 CEST 2008


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




More information about the gstreamer-devel mailing list