[gst-devel] Video thumb nails

Pavan Kumar Patale pavanpatale at hotmail.com
Tue Oct 17 19:46:38 CEST 2006


Hi,

Thanks for the reply.  I tried applying the solution but a blank png image 
comes up.
Seek does not seem to be happening correctly.  Have, appended the code.  Can 
you
pls let me know if i am missing something in it.

Thanks,
Pavan.

>
>I just wanted to note that you may need to turn on these signals by
>setting the fakesink's signal-handoffs property to true.
>~Scott
>
>Michal Benes wrote:
> >> Can anyone pls let me know if there is any support from GStreamer
>framework
> >> to create thumb nails for video files.
> >
> > Hi,
> >
> >     it is not difficult. Just create a pipe
> >
> > filesrc location=source ! decodebin ! ffmpegcolorspace ! pngenc !
> > fakesink
> >
> > and connect to fakesink's preroll-handoff signal. Then put the pipeline
> > to PAUSED state (not PLAYING) and seek to the desired position. Fakesink
> > will give you png screenshot in preroll-handoff callback. Of course you
> > can put videoscale before pngenc to obtain the desired resolution.
> >
> >     Michal
> >


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

static GstElement *pipeline = NULL;
static GMainLoop *loop = NULL;
static GstElement *fsink = NULL;
static GError *error = NULL;

static void preroll_handoff_cb(GstElement * object,
                               GstBuffer * buffer,
                               GstPad * pad, gpointer user_data)
{
    g_print("Starts %s\n", __FUNCTION__);
    FILE *fp = NULL;
    fp = fopen("tnail.png", "wb");
    fwrite(buffer->data, buffer->size, 1, fp);
    fclose(fp);
    g_print("Ends %s\n", __FUNCTION__); }

gint main(gint argc, gchar * argv[])
{
    gst_init(&argc, &argv);

    loop = g_main_loop_new(NULL, TRUE);

    pipeline =      gst_parse_launch ("filesrc location=1.avi ! queue ! 
decodebin ! ffmpegcolorspace ! pngenc ! fakesink name=fsink",  &error);

    if (!pipeline) {
        g_print("Unable to get the pipeline\n");
        return -1;
    }

    if (error) {
        g_print("Error %s\n", error->message);
        g_error_free(error);
        error = NULL;
        return -1;
    }

    fsink = gst_bin_get_by_name(GST_BIN(pipeline), "fsink");

    g_object_set(G_OBJECT(fsink), "signal-handoffs", TRUE, NULL);

    g_signal_connect(G_OBJECT(fsink), "preroll-handoff",  
preroll_handoff_cb, NULL);

    if (!gst_element_set_state(pipeline, GST_STATE_PAUSED)) {
        g_print("Unable to set the state to paused\n");
    }
    if (!gst_element_seek_simple(fsink, GST_FORMAT_BYTES, 
GST_SEEK_FLAG_ACCURATE, 0)) {
        g_print("Unable to seek\n");
    }

    g_print("Inside loop\n");
    g_main_loop_run(loop);
    return 0;
}






More information about the gstreamer-devel mailing list