Trying to understand videorate - Slideshow with PNG images to be produced
Tim-Philipp Müller
t.i.m at zen.co.uk
Sat Jun 29 06:32:16 PDT 2013
On Sat, 2013-06-29 at 03:32 -0300, Luis Mariano Luporini wrote:
Hi Luis,
> I'm trying to understand gstreamer 1.0 (1.0.7 linux to be more specific)
> concepts and I'm noob at this.
>
> I have the following requirement.
>
> 1. Take a list of PNG images
> 2. Convert them to video at a desired FPS, let's say in range 20-30.
> 3. Get to display each image at a desired duration. It will be an
> slideshow where every image should be display during N secs (where N
> will be an integer and can differ between each image)
So first of all, you shouldn't really have to write your own element for
this, but it seems there are some issues in videodecoder and videorate
that don't handle this case properly where there's only a 0 timestamp at
the start and then nothing else. Both should extrapolate based on the
framerate set in the caps.
> To simplify the first implementacion I decided to make N constant for
> every image.
> Then I took the following route to tackle the problem but I finding a
> hard time understanding output and effects of videorate on this.
>
> The context is:
>
> * I have to images named: 01.png and 02.png
> * I will try to read them using multifilesrc and then use my own custom
> plugin to timestamp the two buffers I get from multifilesrc to instruct
> when and for how long I want these images displayed.
> * I decided that N will be 4 for now (4 secs).
> * I decided to test using a FPS of just 2 for this attempt (but
> experimenting with other values -5, 10, 15, 20, 24, 30- give me similar
> not understandable results, at least, for me by now)
> * My pipeline is:
>
> $ gst-launch-1.0 --gst-debug=timedimagefilter2:6 multifilesrc
> location=%02d.png index=1 caps="image/png,framerate=\(fraction\)1/1" !
> pngdec ! timedimagefilter ! videoconvert ! videorate !
> video/x-raw,framerate=\(fraction\)2/1 ! timedimagefilter2 ! timeoverlay
> text="Stream time:" shaded-background=true ! autovideosink
>
> I do the buffers timestamping in "timedimagefilter". this pluging was
> created using the make_element tool presented at the "Guide for Plugin
> Writers", and I only implemented the plugin_chain function that follows:
>
> ----
>
> static GstFlowReturn
> gst_timed_image_filter_chain (GstPad * pad, GstObject * parent,
> GstBuffer * buf)
> {
> GstTimedImageFilter *filter;
> static int buffer_count = 0;
> static GstClockTime last_ts = 0;
> static GstClockTime freeze_const = 0;
>
> filter = GST_TIMEDIMAGEFILTER (parent);
>
> buffer_count++;
>
> if (last_ts == 0) {
> //last_ts = gst_util_uint64_scale_int(4, GST_SECOND, 1);
> }
> if (freeze_const == 0) {
> freeze_const = gst_util_uint64_scale_int(4, GST_SECOND, 1);
> }
> GST_BUFFER_PTS(buf) = last_ts;
> GST_BUFFER_DURATION(buf) = freeze_const;
> last_ts += GST_BUFFER_DURATION(buf);
>
> if (filter->silent == FALSE) {
> GST_DEBUG("[%d] Buffer PTS %" G_GUINT64_FORMAT " - Buffer duration: %"
> G_GUINT64_FORMAT " - Offsets %d - %d", buffer_count,
> GST_BUFFER_PTS(buf), GST_BUFFER_DURATION(buf), GST_BUFFER_OFFSET(buf),
> GST_BUFFER_OFFSET_END(buf));
> }
>
> return gst_pad_push (filter->srcpad, buf);
> }
I think it should be something like:
int fps_num = 5;
int fps_denom = 1;
ts = gst_util_uint64_scale (frame_count,
fps_denom * GST_SECOND, fps_num);
next_ts = gst_util_uint64_scale (frame_count + 1,
fps_denom * GST_SECOND, fps_num);
duration = next_ts - ts;
> ----
>
> Then I just created another plugin to simply print out what buffers it
> gets to better understand whats results the pipeline was producing. The
> plugin name is "timedimagefilter2". It was created following the same
> procedure as the first one and its chain functions follows:
For what it's worth, you can also use fakesink silent=false and identity
silent=false in combination with the -v option of gst-launch-1.0 to make
it print the timestamps of the buffers passing through a pipeline.
Cheers
-Tim
(Haven't really looked at the code or debugged your actual problem, just
commenting from the sidelines)
More information about the gstreamer-devel
mailing list