Can't query to get Position and Duration GStreamer

hungbattran tranhung93.it at gmail.com
Wed Mar 22 17:02:17 UTC 2017


Dear all,

This is my code that I try to get position and duration of video. This code
can play video but it can't query to get position and duration of video.
Please check for me. I'm a newbee of gstreamer and this code I modify from
example 13.
Thank so much.

#include <string.h>
#include <stdio.h>
#include <gst/gst.h>


typedef struct _CustomData {
  GstElement *pipeline;
  GstElement *video_sink;
  GMainLoop *loop;
  
  gint64 position;
  GstEvent *seek_event;

  gboolean playing;  /* Playing or Paused */
  gdouble rate;      /* Current playback rate (can be negative) */
} CustomData;

int main(int argc, char *argv[]) {
  CustomData data;
  GstStateChangeReturn ret;
  GIOChannel *io_stdin;
  GstFormat format = GST_FORMAT_TIME;
 
  GstEvent *seek_event;
  gint64 position;
  gint64 duration;
 


  /* Initialize GStreamer */
  gst_init (&argc, &argv);

  /* Initialize our data structure */
  memset (&data, 0, sizeof (data));

  /* Print usage map */
  

  /* Build the pipeline */
  data.pipeline = gst_parse_launch ("playbin
uri=file:///home/hungtran/Desktop/sintel_trailer-480p.webm", NULL);  
  /* Start playing */
  ret = gst_element_set_state (data.pipeline, GST_STATE_PLAYING);
  if (ret == GST_STATE_CHANGE_FAILURE) {
    g_printerr ("Unable to set the pipeline to the playing state.\n");
    gst_object_unref (data.pipeline);
    return -1;
  }
  data.playing = TRUE;
  data.rate = 1.0;
  
  /* Obtain the current position, needed for the seek event */
  if (!gst_element_query_position (data.pipeline, GST_FORMAT_TIME,
&position)) {
    g_printerr ("Unable to retrieve current position.\n");
    return;
  }

 if (!gst_element_query_duration (data.pipeline, GST_FORMAT_TIME,
&duration)) {
    g_printerr ("Unable to retrieve current position.\n");
    return;
  }
  
    printf("[right] previous=%"GST_TIME_FORMAT"\n",
GST_TIME_ARGS(position));
    printf("[right] previous=%"GST_TIME_FORMAT"\n",
GST_TIME_ARGS(duration));
  
  
  
  
  
  
  
  /* Create a GLib Main Loop and set it to run */
  data.loop = g_main_loop_new (NULL, FALSE);
  g_main_loop_run (data.loop);

  /* Free resources */
  g_main_loop_unref (data.loop);
  g_io_channel_unref (io_stdin);
  gst_element_set_state (data.pipeline, GST_STATE_NULL);
  if (data.video_sink != NULL)
    gst_object_unref (data.video_sink);
  gst_object_unref (data.pipeline);
  return 0;
}



--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Can-t-query-to-get-Position-and-Duration-GStreamer-tp4682359.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.


More information about the gstreamer-devel mailing list