Query the negotiated framerate in the caps - how?

Graham Leggett minfrin at sharp.fm
Fri Aug 21 15:28:48 PDT 2015


Hi all,

I have a gstreamer plugin in which I am trying to read the negotiated framerate, however the framerate I’m getting back is coming back as “variable” (0/1) even though my element appears after the videorate element which in theory should set the framerate:

… ! videorate ! video/x-raw,framerate=25/1 ! videoscale ! video/x-raw,width=384,height=256 ! timeoverlay ! tee name=frame ! …

followed by

frame. ! videotag ! …

First question - with the framerate having been explicitly set by the videorate element, should the videotag element be able to read the negotiated caps and the framerate that was set?

Second question - this is the code that I am using to do this, can you confirm whether this is going to give me the negotiated caps, or if I am doing this the wrong way?

static gboolean
gst_video_tag_sink_event (GstBaseTransform * trans, GstEvent * event)
{
  GstVideoTag *videotag = GST_VIDEO_TAG (trans);

  switch (GST_EVENT_TYPE (event)) {
    case GST_EVENT_CAPS:
    {
      GstTagList *taglist;
      GValue val = G_VALUE_INIT;
      const GstStructure *structure = gst_event_get_structure (event);
      const GValue *fr = gst_structure_get_value(structure, "framerate");
      gint fps_n = 0;
      gint fps_d = 0;

      if (fr) {
        if (G_VALUE_TYPE (fr) == GST_TYPE_FRACTION_RANGE) {
          fr = gst_value_get_fraction_range_min(fr);
        }
        if (fr) {
          fps_n = gst_value_get_fraction_numerator(fr);
          fps_d = gst_value_get_fraction_numerator(fr);
        }
      }
      if (!fps_d) {
        /* unspecified or zero denominator is variable framerate */
        fps_n = 0;
        fps_d = 1;
      }

g_print("CAPS event: framerate %d/%d\n", fps_n, fps_d);

      taglist = gst_tag_list_new_empty ();

      g_value_init (&val, GST_TYPE_FRACTION);
      gst_value_set_fraction (&val, fps_n, fps_d);

      gst_tag_list_add_value (taglist, GST_TAG_MERGE_REPLACE,
         GST_TAG_FRAME_RATE, &val);

      g_value_unset (&val);

      gst_pad_push_event (GST_BASE_TRANSFORM_SRC_PAD (videotag),
         gst_event_new_tag (taglist));

      break;
    }

    default:
      break;
  }
  return GST_BASE_TRANSFORM_CLASS (gst_video_tag_parent_class)->sink_event (trans, event);

  /* ERRORS */
format_error:
  {
    GST_WARNING_OBJECT (videotag,
        "Got segment but doesn't have GST_FORMAT_TIME value");
    return FALSE;
  }
}

The debug output I’m getting looks like this:

Redistribute latency...
CAPS event: framerate 0/1
CAPS event: framerate 0/1
CAPS event: framerate 0/1

Can anyone confirm?

Regards,
Graham
—



More information about the gstreamer-devel mailing list