Howto determine size?
Stefan Kost
ensonic at hora-obscura.de
Tue Jul 5 15:26:09 PDT 2011
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 <stefbon at gmail.com>
>
> 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
> gstreamer-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
More information about the gstreamer-devel
mailing list