Howto determine size?

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

Howto determine size?

Stef Bon
Hi,

I've written a gstreamer program (my first!) . See at bottom of email.

It just plays an mp3 file. What I'm interested in is the progress of
bytes decoded and the final size.
Now the program gives the "size " in seconds, not in bytes. That's not
aproblem, but first the total duration is false:
It should be 2:57 in stead of 3:12.

sbon [ ~/Programmeren/testgst ]$ ./test /home/sbon/Music/The\ Doors\
The\ Ultimate\ Best\ Of\ 2011\ Remastered\ 320\ Kbps/02\ Strange\
Days.mp3
Time: 0:00:05.074126984 / 0:03:12.604200000
(break using Ctrl-C)

When rewriting it to use the bytes, it also does not report the right
size. Instead of the format GST_FORMAT_TIME, I've used
GST_FORMAT_BYTES, and of course another format of the g_print
function. But then a far to small size is reported when printing len.

Futher is works as expected, great.

Stef


/*
  2010, 2011 Stef Bon <[hidden email]>

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/


#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <err.h>
#include <sys/stat.h>
#include <inttypes.h>
#include <sys/types.h>


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

static gboolean cb_reportprogress (GstElement *pipeline)
{
  GstFormat fmt = GST_FORMAT_TIME;
  gint64 pos, len;

    if (gst_element_query_position (pipeline, &fmt, &pos) &&
gst_element_query_duration (pipeline, &fmt, &len)) {

        g_print ("Time: %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT "
\r", GST_TIME_ARGS(pos), GST_TIME_ARGS(len));

    }

    /* call me again */
    return TRUE;

}



int main(int argc, char *argv[])
{
    GMainLoop *loop;
    GstElement *pipeline, *source, *decoder, *conv, *sampler, *sink;

    gst_init(&argc, &argv);

    loop = g_main_loop_new(NULL, FALSE);

    if ( argc != 2 ) {

        g_printerr("Usage: %s <audio file>\n", argv[0]);
        return -1;

    }

    pipeline    = gst_pipeline_new("test-encoder");
    source      = gst_element_factory_make ("filesrc", "file-source");
    decoder     = gst_element_factory_make ("mad", "decoder");
    conv        = gst_element_factory_make ("audioconvert", "converter");
    sampler     = gst_element_factory_make ("audioresample", "sampler");
    sink        = gst_element_factory_make ("alsasink", "audio-output");

    if ( ! pipeline || ! source || ! decoder || ! conv || ! sampler ||
! sink ) {

        g_printerr ("error creating element....\n");
        return -1;

    }


    g_object_set(G_OBJECT(source), "location", argv[1], NULL);

    gst_bin_add_many(GST_BIN(pipeline), source, decoder, conv,
sampler, sink, NULL);

    gst_element_link (source, decoder);
    gst_element_link (decoder, conv);
    gst_element_link (conv, sampler);
    gst_element_link (sampler, sink);

    /*if ( ! gst_element_link_many(decoder, conv, sink, NULL ) ) {

        g_printerr("error linking elements...\n");
        return -1;

    } */

    gst_element_set_state(pipeline, GST_STATE_PLAYING);

    g_timeout_add (500, (GSourceFunc) cb_reportprogress, pipeline);
    g_main_loop_run (loop);

    g_print("Ready...\n");

    gst_element_set_state(pipeline, GST_STATE_NULL);

    gst_object_unref( GST_OBJECT(pipeline));

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

Re: Howto determine size?

Stef Bon
In addition to this, when I've rewritten the progress function to this:

static gboolean cb_reportprogress (GstElement *pipeline)
{
  GstFormat fmt = GST_FORMAT_BYTES;
  gint64 pos, len;

    if (gst_element_query_position (pipeline, &fmt, &pos) &&
gst_element_query_duration (pipeline, &fmt, &len)) {

        g_print ("Pos: %" G_GINT64_FORMAT " / %" G_GINT64_FORMAT "
\r", pos, len);

    }

    /* call me again */
    return TRUE;

}

it reports something like this:

Pos: 14262736 / 67950761

where of course the second number is the total size, which is not
correct. The counter is already bigger than that number.... and is
still counting.

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

Re: Howto determine size?

Stefan Sauer
In reply to this post by Stef Bon
On 07/05/11 01:31, Stef Bon wrote:

> Hi,
>
> I've written a gstreamer program (my first!) . See at bottom of email.
>
> It just plays an mp3 file. What I'm interested in is the progress of
> bytes decoded and the final size.
> Now the program gives the "size " in seconds, not in bytes. That's not
> aproblem, but first the total duration is false:
> It should be 2:57 in stead of 3:12.
>
> sbon [ ~/Programmeren/testgst ]$ ./test /home/sbon/Music/The\ Doors\
> The\ Ultimate\ Best\ Of\ 2011\ Remastered\ 320\ Kbps/02\ Strange\
> Days.mp3
> Time: 0:00:05.074126984 / 0:03:12.604200000
> (break using Ctrl-C)
>
> When rewriting it to use the bytes, it also does not report the right
> size. Instead of the format GST_FORMAT_TIME, I've used
> GST_FORMAT_BYTES, and of course another format of the g_print
> function. But then a far to small size is reported when printing len.

I'd say use decodebin2 directly or also plug mp3parse before mad. Wonder
where the bug come from though, filesrc should report the file-size in
bytes correctly. You could check who answered the duration query.

Stefan

> Futher is works as expected, great.
>
> Stef
>
>
> /*
>   2010, 2011 Stef Bon <[hidden email]>
>
>   This program is free software; you can redistribute it and/or
>   modify it under the terms of the GNU General Public License
>   as published by the Free Software Foundation; either version 2
>   of the License, or (at your option) any later version.
>
>   This program is distributed in the hope that it will be useful,
>   but WITHOUT ANY WARRANTY; without even the implied warranty of
>   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>   GNU General Public License for more details.
>
>   You should have received a copy of the GNU General Public License
>   along with this program; if not, write to the Free Software
>   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
>
> */
>
>
> #include <stdio.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <stddef.h>
> #include <stdbool.h>
> #include <string.h>
> #include <unistd.h>
> #include <fcntl.h>
> #include <errno.h>
> #include <err.h>
> #include <sys/stat.h>
> #include <inttypes.h>
> #include <sys/types.h>
>
>
> #include <gst/gst.h>
> #include <glib.h>
>
> static gboolean cb_reportprogress (GstElement *pipeline)
> {
>   GstFormat fmt = GST_FORMAT_TIME;
>   gint64 pos, len;
>
>     if (gst_element_query_position (pipeline, &fmt, &pos) &&
> gst_element_query_duration (pipeline, &fmt, &len)) {
>
>         g_print ("Time: %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT "
> \r", GST_TIME_ARGS(pos), GST_TIME_ARGS(len));
>
>     }
>
>     /* call me again */
>     return TRUE;
>
> }
>
>
>
> int main(int argc, char *argv[])
> {
>     GMainLoop *loop;
>     GstElement *pipeline, *source, *decoder, *conv, *sampler, *sink;
>
>     gst_init(&argc, &argv);
>
>     loop = g_main_loop_new(NULL, FALSE);
>
>     if ( argc != 2 ) {
>
>         g_printerr("Usage: %s <audio file>\n", argv[0]);
>         return -1;
>
>     }
>
>     pipeline    = gst_pipeline_new("test-encoder");
>     source      = gst_element_factory_make ("filesrc", "file-source");
>     decoder     = gst_element_factory_make ("mad", "decoder");
>     conv        = gst_element_factory_make ("audioconvert", "converter");
>     sampler     = gst_element_factory_make ("audioresample", "sampler");
>     sink        = gst_element_factory_make ("alsasink", "audio-output");
>
>     if ( ! pipeline || ! source || ! decoder || ! conv || ! sampler ||
> ! sink ) {
>
>         g_printerr ("error creating element....\n");
>         return -1;
>
>     }
>
>
>     g_object_set(G_OBJECT(source), "location", argv[1], NULL);
>
>     gst_bin_add_many(GST_BIN(pipeline), source, decoder, conv,
> sampler, sink, NULL);
>
>     gst_element_link (source, decoder);
>     gst_element_link (decoder, conv);
>     gst_element_link (conv, sampler);
>     gst_element_link (sampler, sink);
>
>     /*if ( ! gst_element_link_many(decoder, conv, sink, NULL ) ) {
>
>         g_printerr("error linking elements...\n");
>         return -1;
>
>     } */
>
>     gst_element_set_state(pipeline, GST_STATE_PLAYING);
>
>     g_timeout_add (500, (GSourceFunc) cb_reportprogress, pipeline);
>     g_main_loop_run (loop);
>
>     g_print("Ready...\n");
>
>     gst_element_set_state(pipeline, GST_STATE_NULL);
>
>     gst_object_unref( GST_OBJECT(pipeline));
>
>     return 0;
> _______________________________________________
> 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
Reply | Threaded
Open this post in threaded view
|

Re: Howto determine size?

Tim-Philipp Müller-2
On Tue, 2011-07-05 at 15:26 -0700, Stefan Kost wrote:

> I'd say use decodebin2 directly or also plug mp3parse before mad. Wonder
> where the bug come from though, filesrc should report the file-size in
> bytes correctly. You could check who answered the duration query.

Just on a side note, it's not really clear that a query for the duration
in BYTES on the source pad of an audio decoder should actually yield the
size of the compressed data. It should really yield the size of the
uncompressed audio data, so sample_size_in_bytes * channels *
samples_per_second * seconds.

Cheers
 -Tim


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

Re: Howto determine size?

Stef Bon
In reply to this post by Stefan Sauer
2011/7/6 Stefan Kost <[hidden email]>:

> On 07/05/11 01:31, Stef Bon wrote:
>> Hi,
>>
>> I've written a gstreamer program (my first!) . See at bottom of email.
>>
>> It just plays an mp3 file. What I'm interested in is the progress of
>> bytes decoded and the final size.
>> Now the program gives the "size " in seconds, not in bytes. That's not
>> aproblem, but first the total duration is false:
>> It should be 2:57 in stead of 3:12.
>>
>> sbon [ ~/Programmeren/testgst ]$ ./test /home/sbon/Music/The\ Doors\
>> The\ Ultimate\ Best\ Of\ 2011\ Remastered\ 320\ Kbps/02\ Strange\
>> Days.mp3
>> Time: 0:00:05.074126984 / 0:03:12.604200000
>> (break using Ctrl-C)
>>
>> When rewriting it to use the bytes, it also does not report the right
>> size. Instead of the format GST_FORMAT_TIME, I've used
>> GST_FORMAT_BYTES, and of course another format of the g_print
>> function. But then a far to small size is reported when printing len.
>
> I'd say use decodebin2 directly or also plug mp3parse before mad. Wonder
> where the bug come from though, filesrc should report the file-size in
> bytes correctly. You could check who answered the duration query.

Thanks for your reply,

I've added mp3parse, and now I get more sensible output.

I would like to use the decoder/encoder encodebin, but that requires a
profile. Can you give an example of that?

Stef
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel