decodebin and single frame images

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

decodebin and single frame images

Steffen.Roeber
Hui,
I'm using a filesrc, a decodebin2 and a appsink. If I use .avi file sall is fine. If I use image files like .bmp or .png the app sink gives me the image only one time. Following calls always return 0.
What I want to have is to retrieve the image in a loop. Seeking the pipeline to 0 seems not to work.
Is there any way to get this behaviour?

Regards


Hella Aglaia Mobile Vision GmbH
Steffen Roeber
Firmware & Tools
Treskowstr. 14, D-13089 Berlin
Amtsgericht Berlin-Charlottenburg HRB 66976 B
Geschäftsführer: Kay Talmi

Fon:  +49 30 200 04 29– 412
Fax:  +49 30 200 04 29– 109
Mail: [hidden email]
URL:
www.aglaia-gmbh.de

URL:
www.mobilevision.de

Dieses Dokument ist vertraulich zu behandeln. Die Weitergabe sowie Vervielfältigung, Verwertung und Mitteilung seines Inhalts ist nur mit unserer ausdrücklichen Genehmigung gestattet. Alle Rechte vorbehalten, insbesondere für den Fall der Schutzrechtsanmeldung.
This document has to be treated confidentially. Its contents are not to be passed on, duplicated, exploited or disclosed without our express permission. All rights reserved, especially the right to apply for protective rights.

_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: decodebin and single frame images

Sergei Vorobyov
RE: still images as movies howto

Try

gst-launch filesrc location=file.png ! decodebin2 ! imagefreeze !
ffmpegcolorspace ! autovideosink

You may replace the last sink with ximagesink, xvimagesink, or similar.

If you need the corresponding C code, it roughly looks as this:

...

  gst_init (&argc, &argv);
  loop = g_main_loop_new (NULL, FALSE);
  pipeline = gst_pipeline_new ("Still video player");
  src =  gst_element_factory_make ("filesrc", "source_image");
  dec =  gst_element_factory_make ("pngdec", "decode_bin");
  img_freeze = gst_element_factory_make ("imagefreeze", "image_freeze");
  conv = gst_element_factory_make ("ffmpegcolorspace", "ffmpeg-colorspace");
  sink = gst_element_factory_make ("ximagesink", "directdrawsink-output");

  if (!loop || !pipeline || !src || !img_freeze || !conv || !sink) {
    g_print ("Some element could not be created\n");
    return -1;
  }

  g_object_set (src, "location", argv[1], NULL); // plug in your file
name instead of argv[1] if needed

  gst_bin_add_many (GST_BIN (pipeline),
                    src,
                    dec,
                    img_freeze,
                    conv,
                    sink,  NULL);

  gst_element_link_many (src, dec, img_freeze, conv, sink, NULL);

  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  gst_bus_add_watch (bus, bus_call, loop); // callback bus call -> see below
  gst_object_unref (bus);

  // Variant 1:
  // Will stop still image playing after 5 sec
  // g_timeout_add_seconds (5, (GSourceFunc) cb_end_stream, pipeline);
// callback cb_end_stream -> see below

  // Variant 2: also stops after 5 sec
  GstEvent *event = gst_event_new_seek (1.0,
                              GST_FORMAT_TIME,
                              GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SEGMENT,
                              GST_SEEK_TYPE_SET, 0 * GST_SECOND,
                              GST_SEEK_TYPE_SET, 5 * GST_SECOND);

  gst_element_set_state (pipeline, GST_STATE_PLAYING);

  if (!gst_element_send_event(pipeline, event)) { // this will cause
...MESSAGE_SEGMENT_DONE in the callback
    g_print("failure to seek\n");
    return -1;
  }

  /* now run */
  g_main_loop_run (loop);

  /* finally clean up */
  gst_element_set_state (pipeline, GST_STATE_NULL);
  gst_object_unref (GST_OBJECT (pipeline));

  return 0;
}

gboolean cb_end_stream (GstElement *pipeline) {
  g_main_loop_quit(loop);
  return FALSE;
}

gboolean bus_call (GstBus  *bus, GstMessage *msg, gpointer  data) {
    GMainLoop *loop = (GMainLoop *) data;

    guint msg_type = GST_MESSAGE_TYPE (msg);

    if (msg_type & GST_MESSAGE_EOS) {
      g_print ("EOS message\n");
      g_main_loop_quit (loop);
    }

...

    if (msg_type & GST_MESSAGE_STATE_CHANGED) { // quite useful, for debugging
      g_print ("STATE CHANGED message, to state %d\n",
                GST_STATE(GST_MESSAGE_SRC(msg)));

      GstState old_state, new_state;

      gst_message_parse_state_changed (msg, &old_state, &new_state, NULL);
      g_print ("Element %s changed state from %s to %s.\n",
        GST_OBJECT_NAME (msg->src),
        gst_element_state_get_name (old_state),
        gst_element_state_get_name (new_state)); // I think you should
be more careful here to free ..._gets_
    }

...

    if (msg_type & GST_MESSAGE_SEGMENT_DONE) {
      g_print ("SEGMENT DONE message\n");
      g_main_loop_quit (loop);
    }

...

    return TRUE;
}

I am not a specialist, but hope it helps. The docs are scarce on
examples, explanations, and use cases. It also took me some to me to
figure.

On Thu, Mar 29, 2012 at 4:31 PM,  <[hidden email]> wrote:

> Hui,
> I'm using a filesrc, a decodebin2 and a appsink. If I use .avi file sall is
> fine. If I use image files like .bmp or .png the app sink gives me the image
> only one time. Following calls always return 0.
> What I want to have is to retrieve the image in a loop. Seeking the pipeline
> to 0 seems not to work.
> Is there any way to get this behaviour?
>
> Regards
>
>
> Hella Aglaia Mobile Vision GmbH
> Steffen Roeber
> Firmware & Tools
> Treskowstr. 14, D-13089 Berlin
> Amtsgericht Berlin-Charlottenburg HRB 66976 B
> Geschäftsführer: Kay Talmi
>
> Fon:  +49 30 200 04 29– 412
> Fax:  +49 30 200 04 29– 109
> Mail: [hidden email]
> URL: www.aglaia-gmbh.de
>
> URL: www.mobilevision.de
>
> Dieses Dokument ist vertraulich zu behandeln. Die Weitergabe sowie
> Vervielfältigung, Verwertung und Mitteilung seines Inhalts ist nur mit
> unserer ausdrücklichen Genehmigung gestattet. Alle Rechte vorbehalten,
> insbesondere für den Fall der Schutzrechtsanmeldung.
> This document has to be treated confidentially. Its contents are not to be
> pass ed on, duplicated, exploited or disclosed without our express
> permission. All rights reserved, especially the right to apply for
> protective rights.
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
>
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel