<html><head></head><body><div>On Tue, 2020-11-10 at 12:24 +0500, Hassan Muhammad wrote:</div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;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">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">https://www.centricular.com</a></div><div><br></div></span></div></body></html>