How get buffer width, height from Gstreamer Caps

     Next lines of code helps to get buffer width, height from Gst.Caps for further buffer processing. In general, Caps are simple description of media formats and consists of multiple Gst.Structures

#1. Take Zero Structure from caps

caps_struct = caps.get_structure(0)

#2. Query width from Structure using get_int

(success, width) = caps_struct.get_int('width')

#3. Query height from Structure

(success, height) = caps_struct.get_int('height')

     Here is full code for simple function that gets width, height from Caps.

def get_buffer_size(caps):
    """
        Returns width, height of buffer from caps

        :param caps: https://lazka.github.io/pgi-docs/Gst-1.0/classes/Caps.html
        :type caps: Gst.Caps

        :rtype: bool, (int, int)
     """

    caps_struct = caps.get_structure(0)

    (success, width) = caps_struct.get_int('width')
    if not success:
        return False, (0, 0)

    (success, height) = caps_struct.get_int('height')
    if not success:
        return False, (0, 0)

    return True, (width, height)

     How to get caps inside Custom Gstreamer Plugin?

self.srcpad.get_current_caps()
self.sinkpad.get_current_caps()

     Further readings:

Add a Comment

Your email address will not be published. Required fields are marked *