Query duration of many sound files in a loop

Jiergir Ogoerg f35f22fan at gmail.com
Tue Aug 20 13:49:27 PDT 2013


Didn't find it before cause I was looking for libgstreamer1-..

thanks, it works, with this API I can even get fancy stuff like bitrate,
which is cool.

For future users learning Gstreamer I wish GstElement's get duration method
documentation would mention the discoverer API.

Since it's in C to me as a user it slightly sucks having to cast objects
back and forth and mix and match different delete functions for each case
like
g_object_unref
gst_discoverer_info_unref
gst_discoverer_stream_info_list_free
etc.

Anyway, here's my final code which (to me) works correctly, thanks a lot!

//SOURCE START
    for (int i=0; i<vec_size; i++) {
        mtl::io::QtFile *file = (*vec)[i];

        if (file->IsDir()) { // not a sound file
            delete file;
            continue;
        }

        QString uri = "file://" + file->full_path();
        QByteArray arr = uri.toLocal8Bit();
        const char *c_uri = arr.data();

        discov_info = gst_discoverer_discover_uri(discov, c_uri, NULL);
        if (discov_info == NULL) {
            MTL_WARN("discov_info = NULL");
            break;
        }

        duration = (int64_t) gst_discoverer_info_get_duration(discov_info);

        GList *list = gst_discoverer_info_get_stream_list(discov_info);
        if (list == NULL) {
            MTL_WARN("list = NULL");
            break;
        }

        auto *stream_info = (const GstDiscovererStreamInfo*)list->data;
        if (stream_info == NULL) {
            MTL_WARN("stream_info = NULL");
            break;
        }

        auto *audio_info = (const GstDiscovererAudioInfo*)stream_info;
        uint32_t bitrate =
gst_discoverer_audio_info_get_bitrate(audio_info);
        gst_discoverer_stream_info_list_free(list);
        gst_discoverer_info_unref(discov_info);

        file->duration_set(duration);
        file->bitrate_set(bitrate);
        song_tree->AddSong(file);
    }

    g_object_unref(discov);
// SOURCE END





On Tue, Aug 20, 2013 at 3:13 PM, Tim-Philipp Müller <t.i.m at zen.co.uk> wrote:

> On Tue, 2013-08-20 at 06:27 +0300, Jiergir Ogoerg wrote:
>
> > Thanks, the GstDiscoverer seems just what I need, after like 20
> > minutes of searching the repos, googling etc
> >
> > I can't figure out where it's stored and how to install it, looks like
> > Ubuntu doesn't support it.
> >
> > Do you know what's the package (dev) name I have to install?
> >
> >
> > In particular, I got libgstreamer1-dev installed, there are no other
> > "-dev" packages related to gstreamer1.0 in Ubuntu.
>
> libgstreamer-plugins-base1.0-dev
>
> > apt-cache search pbutils - yields nothing.
>
> Something to take up with the packagers, I think.
>
> Cheers
>  -Tim
>
>
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20130820/0bda3010/attachment.html>


More information about the gstreamer-devel mailing list