Understanding the example with appsrc

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Understanding the example with appsrc

Wudo Balmus
Hello,
I'm trying to understand the example for appsrc element described in the official tutorial:

https://gstreamer.freedesktop.org/documentation/application-development/advanced/pipeline-manipulation.html

We specify caps like that:

 g_object_set (G_OBJECT (appsrc), "caps",
        gst_caps_new_simple ("video/x-raw",
                     "format", G_TYPE_STRING, "RGB16",
                     "width", G_TYPE_INT, 384,
                     "height", G_TYPE_INT, 288,
                     "framerate", GST_TYPE_FRACTION, 0, 1,
                     NULL), NULL);

Then, when need-data function is called, there is created a GstBuffer of size:

size = 385 * 288 * 2;

filled with some color and pushed to appsrc.

Two questions:

1. Why there is component 385, not 384 in the size of the buffer? In caps there was specified that the width is 384, but in the size of the buffer 385 appeared.
2. Why the size is multiplied by 2? Cannot we just send 1 frame? I tried to remove the *2 component, but then the background becomes a different colour than expected.
I tried also to modify duration, to make it 1fps, but still doesn't work.

Best regards,
Wudo

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Understanding the example with appsrc

Wudo Balmus
It looks like that the component *2 is because in RGB16 1pixel is 2 bytes, so the 384*288 pixmap requires 384*288*2 bytes. Still wondering why there is 385, not 384.

pon., 18 lut 2019 o 22:10 Wudo Balmus <[hidden email]> napisał(a):
Hello,
I'm trying to understand the example for appsrc element described in the official tutorial:

https://gstreamer.freedesktop.org/documentation/application-development/advanced/pipeline-manipulation.html

We specify caps like that:

 g_object_set (G_OBJECT (appsrc), "caps",
        gst_caps_new_simple ("video/x-raw",
                     "format", G_TYPE_STRING, "RGB16",
                     "width", G_TYPE_INT, 384,
                     "height", G_TYPE_INT, 288,
                     "framerate", GST_TYPE_FRACTION, 0, 1,
                     NULL), NULL);

Then, when need-data function is called, there is created a GstBuffer of size:

size = 385 * 288 * 2;

filled with some color and pushed to appsrc.

Two questions:

1. Why there is component 385, not 384 in the size of the buffer? In caps there was specified that the width is 384, but in the size of the buffer 385 appeared.
2. Why the size is multiplied by 2? Cannot we just send 1 frame? I tried to remove the *2 component, but then the background becomes a different colour than expected.
I tried also to modify duration, to make it 1fps, but still doesn't work.

Best regards,
Wudo

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Understanding the example with appsrc

Tim Müller
On Mon, 2019-02-18 at 22:52 +0000, Wudo Balmus wrote:

Hi Wudo,

> It looks like that the component *2 is because in RGB16 1pixel is 2
> bytes, so the 384*288 pixmap requires 384*288*2 bytes.

That's right.

>  Still wondering why there is 385, not 384.

I think it's just a typo, it should probably be 384 as well.

Another/better way would be to use e.g.

GstVideoInfo vinfo;

gst_video_info_set_format (&vinfo, GST_FORMAT_RGB16, 384, 288);

size = GST_VIDEO_INFO_SIZE (&vinfo);

(or even a GstVideoBufferPool).

Cheers
 Tim

--
Tim Müller, Centricular Ltd - http://www.centricular.com

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Understanding the example with appsrc

Nicolas Dufresne-5
In reply to this post by Wudo Balmus


Le lun. 18 févr. 2019 17 h 13, Wudo Balmus <[hidden email]> a écrit :
Hello,
I'm trying to understand the example for appsrc element described in the official tutorial:

https://gstreamer.freedesktop.org/documentation/application-development/advanced/pipeline-manipulation.html

We specify caps like that:

 g_object_set (G_OBJECT (appsrc), "caps",
        gst_caps_new_simple ("video/x-raw",
                     "format", G_TYPE_STRING, "RGB16",
                     "width", G_TYPE_INT, 384,
                     "height", G_TYPE_INT, 288,
                     "framerate", GST_TYPE_FRACTION, 0, 1,
                     NULL), NULL);

Then, when need-data function is called, there is created a GstBuffer of size:

size = 385 * 288 * 2;

filled with some color and pushed to appsrc.

Two questions:

1. Why there is component 385, not 384 in the size of the buffer? In caps there was specified that the width is 384, but in the size of the buffer 385 appeared.

385 is a typo, all the rest of the code uses 384. But as this will do overallocation it should not cause any issue, would be nice to open an issue against gst-docs, as this is confusing.

2. Why the size is multiplied by 2? Cannot we just send 1 frame? I tried to remove the *2 component, but then the background becomes a different colour than expected.

2 is the number of bytes per pixels for the chosen format. So width*height*bps = size. Note though that in GStreamer you will have to round up the width to a multiple of 2.

I tried also to modify duration, to make it 1fps, but still doesn't work.

The frame duration would also need to be set on buffers along with valid timestamp.


Best regards,
Wudo
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel