<div dir="ltr">Thank you for your prompt response. It has been really helpful. I have taken a look over the plugin writing tutorial that you have referenced and it seems to me that this may be the most appropriate solution to modifying buffers in a non-intrusive manner i.e. within an element between source and sink pads. One thing I'd like to ask is, would mapping buffer read/writable and performing some operation on the buffer (i.e. like you did converting BGRx colorspace to GRAY8) impose any significant performance penalty on the pipeline when specifically rendering HD or FHD videos?<div>Sorry if this seems like a silly question, I'm actually new to gstreamer and only starting to get the hang of how it works. Thanks again for your help.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 10, 2020 at 6:00 PM Sebastian Dröge <<a href="mailto:sebastian@centricular.com">sebastian@centricular.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div>On Tue, 2020-11-10 at 12:24 +0500, Hassan Muhammad wrote:</div><blockquote type="cite" style="margin:0px 0px 0px 0.8ex;border-left:2px solid rgb(114,159,207);padding-left:1ex"><div>Hi. I am new to gstreamer and trying to figure out a way to read buffers from a video source, modifying the buffers in some way (e.g. draw overlay information) and output the buffers to a video or filesink. I am using the gstreamer-rust bindings and have not been able to find a solution to this problem. Reading on the forums, I tried to add a pad probe at the source element of the following pipeline as a test by getting the static pad: </div><div><br></div><div>"videotestsrc ! autovideosink"</div><div><br></div><div>I am able to read the buffer from "probe_info.data" :</div><div><br></div><div>src_pad.add_probe(gst::PadProbeType::BUFFER, |_, probe_info| {</div><div>___READ BUFFER___</div><div>}</div><div><br></div><div>However, if I try to map the buffer as writable by using gst::buffer::BufferRef::map_writeable()</div><div><br></div><div><br></div><div>it doesn't allow me to do so with the error "cannot borrow as mutable". At this point I am completely lost and unable to find an alternative to read and modify a buffer element through a pad probe. Any help or suggestion would be appreciated to help me overcome this.</div></blockquote><div><br></div><div>The following should work</div><div><br></div><pre>    src_pad.add_probe(gst::PadProbeType::BUFFER, |_, probe_info| {</pre><pre>        if let Some(gst::PadProbeData::Buffer(ref mut buffer)) = probe_info.data {</pre><pre>            let buffer = buffer.make_mut();</pre><pre><br></pre><pre>            let map = buffer.map_writable().unwrap();</pre><pre>            [do things with `map`] </pre><pre>        }</pre><pre>        gst::PadProbeReturn::Ok</pre><pre>    });</pre><div><br></div><div>You need to get a mutable reference to the `gst::Buffer` from the `probe_info`, and then make sure that its content is actually writable and get a `&mut gst::BufferRef` to modify it via `make_mut()`.</div><div>Then you can map it writable, change the PTS/DTS etc.</div><div><br></div><div><br></div><div>However for modifying buffers (e.g. to add an overlay), it would be better to write a new element for that or make use of the `overlaycomposition` element.</div><div><br></div><div>For the former you can find various examples in gst-plugins-rs, for the latter you can find an example here:</div><div>    <a href="https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/master/examples/src/bin/overlay-composition.rs" target="_blank">https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/master/examples/src/bin/overlay-composition.rs</a></div><div><br></div><div><span><pre>-- <br></pre><div>Sebastian Dröge, Centricular Ltd · <a href="http://www.centricular.com" target="_blank">https://www.centricular.com</a></div><div><br></div></span></div></div>
_______________________________________________<br>
gstreamer-devel mailing list<br>
<a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">gstreamer-devel@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><br>
</blockquote></div>