[gst-devel] pixbuf from video file

Luis de Bethencourt bethencourt at gmail.com
Thu Sep 20 02:24:52 CEST 2007


This is my progress till now... I get the buffer but it is in YUV, and
for the pixbuf I need it in RGB. So anybody knows how to translate a
yuv buffer to rgb?

-------------------------------------------------------------------------------------------------------

#include <gst/gst.h>
#include <gtk/gtk.h>

GstElement *play, *fakesink;

int
main (int   argc,
      char *argv[])
{
  GMainLoop *loop;
  GstBuffer *buffer;
  GdkPixbuf *pixbuf;
  GstCaps *caps;
  GstPad *pad;

  GtkWidget *window, *button, *image;

  gst_init (&argc, &argv);
  loop = g_main_loop_new (NULL, FALSE);

  play = gst_element_factory_make ("playbin", "play");
  g_object_set (G_OBJECT (play), "uri", argv[1], NULL);

  fakesink = gst_element_factory_make("fakesink", "fakesink");

  g_object_set (G_OBJECT (play), "video-sink", fakesink, NULL);

  gst_element_set_state (play, GST_STATE_PAUSED);
  GstStateChangeReturn stateChange =
    gst_element_get_state (play, NULL, NULL, GST_CLOCK_TIME_NONE);
  if (stateChange ==  GST_STATE_CHANGE_SUCCESS){
    g_print("State change success\n");
  } else {
    g_print("State changed failed\n");
  }

  g_object_get (G_OBJECT(play), "frame",  &buffer, NULL);

  pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer),
		GDK_COLORSPACE_RGB, FALSE, 8, 120, 90,
		GST_ROUND_UP_4 (120 * 3), NULL, NULL);

  g_print ("Returned, stopping playback\n");
  gst_element_set_state (play, GST_STATE_NULL);
  g_print ("Deleting pipeline\n");
  gst_object_unref (GST_OBJECT (play));

  gtk_init (&argc, &argv);
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  button = gtk_button_new();
  image = gtk_image_new_from_pixbuf(pixbuf);
  gtk_button_set_image(GTK_BUTTON (button), GTK_WIDGET (image));
  gtk_container_add (GTK_CONTAINER (window), button);
  gtk_widget_show (button);
  gtk_widget_show (window);
  gtk_main ();

  return 0;
}

--------------------------------------------------------------------------------------------------------

As suggested in the irc channel I substituted the video-sink of
playbin with a ffmpecolorspace to convert it to RGB, but the frame
property buffer is before this video-sink so I could translate to
sink, but not for buffer.

This is really close as a conversion of the buffer is the only thing
pending, once the code is finished and working I promise I will adapt
it so it works nicely as a function than new gstreamer users can call
for their thumbnailing.

Thanks,
Luis de Bethencourt



On 9/18/07, Luis de Bethencourt <bethencourt at gmail.com> wrote:
> I'm trying this other code now:
>
> -------------------------------------------------------------------------------------------------------
>
>         play = gst_element_factory_make ("playbin", "play");
>         g_object_set (G_OBJECT (play), "uri", file_src, NULL);
>
>         bus = gst_pipeline_get_bus (GST_PIPELINE (play));
>         gst_bus_add_watch (bus, bus_call, loop);
>         gst_object_unref (bus);
>
>   gst_element_set_state (play, GST_STATE_PLAYING);
>
>         //gst_element_set_state (pipeline, GST_STATE_PAUSED);
>         gst_element_get_state (play, NULL, NULL, -1);
>         gst_element_seek_simple(play, GST_FORMAT_TIME,
>                 GST_SEEK_FLAG_KEY_UNIT, 100);
>
>         g_object_get (play, "frame", &buffer, NULL);
>
>         pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer),
>                 GDK_COLORSPACE_RGB, FALSE, 8, 120, 90,
>                 GST_ROUND_UP_4 (120 * 3), NULL, buffer);
>
> -------------------------------------------------------------------------------------------------------
>
> But it seams like the yuv to rgb is not done properly.
> Any suggestions,
>
> Luis de Bethencourt
>
> On 9/18/07, Luis de Bethencourt <bethencourt at gmail.com> wrote:
> > Help!!
> >
> > After 5 days running in circles with this problem, and trying a few
> > different approaches suggested in the irc channel. I don't get this to
> > work at all, I'm getting terribly frustrated and desperate. I really
> > need this thumbnailer for my project.
> >
> > This is my code:
> >
> > -----------------------------------------------------------------------------------------------------
> >
> >         pipeline = gst_pipeline_new ("pipeline");
> >         play = gst_bin_new ("my_bin");
> >
> >         src = gst_element_factory_make ("filesrc", "source");
> >         g_object_set (G_OBJECT (src), "location", file_src, NULL);
> >
> >         parser = gst_element_factory_make ("decodebin", "mpeg-parser");
> >         decoder = gst_element_factory_make ("ffmpegcolorspace", "mpeg-decoder");
> >         videoscale = gst_element_factory_make ("videoscale", "videoscale");
> >         g_object_set (G_OBJECT (videoscale),
> >                 "video/x-raw-rgb,width=640,height=480,bpp=24,depth=24", NULL);
> >         fakesink = gst_element_factory_make ("fakesink", NULL);
> >
> >         if (!pipeline || !src || !parser || !decoder || !videoscale || !fakesink) {
> >                 g_print ("One element could not be created\n");
> >         }
> >
> >         bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
> >         gst_bus_add_watch (bus, bus_call, loop);
> >         gst_object_unref (bus);
> >
> >         gst_bin_add_many (GST_BIN (play),
> >                 src, parser, decoder, videoscale, fakesink, NULL);
> >         gst_bin_add (GST_BIN (pipeline), play);
> >
> >         gst_element_link (source, parser);
> >         gst_element_link_many (decoder, videoscale, fakesink, NULL);
> >         g_signal_connect (parser, "pad-added", G_CALLBACK (new_pad), NULL);
> >
> >         //gst_element_set_state (pipeline, GST_STATE_PAUSED);
> >         gst_element_get_state (pipeline, NULL, NULL, -1);
> >         gst_element_seek_simple(pipeline, GST_FORMAT_PERCENT,
> >                 GST_SEEK_FLAG_KEY_UNIT, 500000);
> >
> >         g_object_get (play, "frame", &buffer, NULL);
> >
> >         pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer),
> >                 GDK_COLORSPACE_RGB, FALSE, 8, 120, 90,
> >                 GST_ROUND_UP_4 (120 * 3), NULL, buffer);
> >
> > ------------------------------------------------------------------------------------------------------
> >
> > And this are the problems I'm getting:
> > object class `GstBin' has no property named `frame'
> > object class `GstVideoScale' has no property named
> > `video/x-raw-rgb,width=640,height=480,bpp=24,depth=24'
> > assertion `GST_IS_ELEMENT (src)' failed
> > and then probably the buffer format will be wrong.
> >
> > I will deeply thank any help,
> > Luis de Bethencourt
> >
> >
> > On 8/6/07, David Schleef <ds at schleef.org> wrote:
> > > On Thu, Aug 02, 2007 at 01:15:30PM +0200, Fredrik Persson wrote:
> > > > To make it absolutely clear; I think that the gstreamer developers are doing
> > > > a great job!
> > > >
> > > > I also absolutely think that they also appreciate "user input" (in this
> > > > case, mine and Luis') on what features we'd like to see in gstreamer.
> > > > Therefore, I like to take the opportunity to bring up this suggestion again.
> > > > I think that every time this question is brought up here on the mailinglist
> > > > is strengthens the point that a "snapshot element" in gstreamer is a good
> > > > idea and that it would increase the attractiveness of the entire gstreamer
> > > > framework.
> > >
> > > It's also a FAQ that can be answered with a simple mailing list search:
> > >
> > >   http://search.gmane.org/?query=thumbnails&group=gmane.comp.video.gstreamer.devel
> > >
> > >
> > >
> > > dave...
> > >
> > >
> > >
> >
> >
> > --
> > Luis de Bethencourt Guimerá
> > luisbg
> > <bethencourt at gmail.com>
> > GPG: B0ED1326
> >
>
>
> --
> Luis de Bethencourt Guimerá
> luisbg
> <bethencourt at gmail.com>
> GPG: B0ED1326
>


-- 
Luis de Bethencourt Guimerá
luisbg
<bethencourt at gmail.com>
GPG: B0ED1326




More information about the gstreamer-devel mailing list