how to get video duration
kilamski
malik.cisse at gmx.net
Sun Jun 23 09:44:32 UTC 2019
Thank you for the feedback Nicolas,
i finally managed to do it with a code that is similar to the one you
attached.
Here is it is for completeness:
int get_ts_file_duration(char *path)
{
GstDiscoverer *discoverer;
GError *err = NULL;
gchar *uri;
unsigned long duration;
uri = gst_filename_to_uri (path, &err);
if (err)
{
g_print ("Error in gst_filename_to_uri(). file: %s: %s\n", path,
err->message);
g_error_free (err);
return -1;
}
/* Initialize GStreamer */
gst_init (NULL, NULL);
/* Instantiate the Discoverer */
discoverer = gst_discoverer_new (1 * GST_SECOND, &err);
if (!discoverer)
{
g_print ("Error creating discoverer instance: %s\n", err->message);
g_error_free (err);
return -1;
}
GstDiscovererInfo *info = gst_discoverer_discover_uri(discoverer, uri,
&err);
if (err)
{
g_print ("Seems file: %s is brocken: %s\n", uri, err->message);
g_error_free (err);
return -1;
}
/* If we got no error, show the retrieved information */
duration = gst_discoverer_info_get_duration (info);
duration /= 1000000000;//duration is in nanoseconds
/* Free resources */
g_object_unref (discoverer);
gst_discoverer_info_unref(info);
g_free(uri);
return (int)duration;
}
--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
More information about the gstreamer-devel
mailing list