<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hello Matteo<div class=""><br class=""></div><div class="">OpenCV video capture will, sadly, copy the frame when taken out of the appsink. This is likely one of the causes of the high CPU consumption. I have proposed a PR to OpenCV in order to fix this, which they reviewed but I haven't gotten the time to continue. You may find the PR here:</div><div class=""><br class=""></div><div class=""><a href="https://github.com/opencv/opencv/pull/18377" class="">https://github.com/opencv/opencv/pull/18377</a></div><div class=""><br class=""></div><div class="">If you'd like to try this out, you'll need to build OpenCV from scratch. Here are some instructions:</div><div class=""><br class=""></div><div class=""><a href="https://developer.ridgerun.com/wiki/index.php?title=Compiling_OpenCV_from_Source" class="">https://developer.ridgerun.com/wiki/index.php?title=Compiling_OpenCV_from_Source</a></div><div class=""><br class=""></div><div class="">Make sure you choose the correct branch and that you enabled GStreamer before launching the build, because it takes a few hours. This branch is now a bit behind master, but should be easy enough to update. I may do it myself in the next few days.</div><div class=""><br class=""></div><div class="">Please find some extra answers inline.</div><div class=""><br class=""></div><div class="">Michael</div><div class=""><a href="http://www.ridgerun.com" class="">www.ridgerun.com</a><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 15 Oct 2021, at 08:44, Matteo Foglio via gstreamer-devel <gstreamer-devel@lists.freedesktop.org> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Good morning,<div class=""><br class=""></div><div class="">I am trying to decode several video streams using GStreamer and Python. I can't tell you how much I will appreciate your help!</div><div class=""><br class=""></div><div class="">Here's my code:<br class=""><br class=""></div><div class=""><pre class="gmail-highlight gmail-code" lang="plaintext"><span id="gmail-LC1" class="gmail-line" lang="plaintext">self.video_capture = cv2.VideoCapture(self.pipeline, cv2.CAP_GSTREAMER)</span>
<span id="gmail-LC2" class="gmail-line" lang="plaintext">if self.video_capture.isOpened() is False:</span>
<span id="gmail-LC3" class="gmail-line" lang="plaintext">    raise Error</span>
<span id="gmail-LC4" class="gmail-line" lang="plaintext">while True:</span>
<span id="gmail-LC5" class="gmail-line" lang="plaintext">    status, image = self.video_capture.read()</span>
<span id="gmail-LC6" class="gmail-line" lang="plaintext">    # do slow stuff</span>
</pre><pre class="gmail-highlight gmail-code" lang="plaintext"><br class=""></pre>I am encountering the following issue:<br class=""><br class=""></div><div class=""><b class="">Option 1</b></div><div class="">If I use the pipeline:</div><div class=""><code class="">self.pipeline = f"rtspsrc location={self.url} latency=10 ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! appsink max-buffers=1 drop=true"</code><br class=""></div><div class=""><br class=""></div><div class="">I get extremely high CPU consumption. Also, I am probably decoding more frames than the number my application can actually consumes.</div><div class=""><br class=""></div></div></div></blockquote><div><br class=""></div><div>Sadly, you are receiving a live compressed feed, which means you cannot drop frames before decoding. If you do so your stream may become momentarily corrupted. You can only drop after decoding. Hopefully you can lower the CPU consumption avoiding the memory copy mentioned above.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class=""><b class="">Option 2</b></div><div class="">If I use this pipeline</div><div class=""><code class="">self.pipeline = f"rtspsrc location={self.url} latency=10 ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! appsink max-buffers=1 drop=false"</code><br class=""></div><div class=""><br class=""></div><div class="">After a few hours the application is returning me old frames. E.g. at 9am my application was receiving frames at nighttime (from the night before).</div><div class=""><br class=""></div></div></div></blockquote><div><br class=""></div><div>Yeah, likely everything is being queued somewhere. As you said, sounds like your app is consuming at a lower rate than you are receiving RTSP frames. You need to drop somewhere in your pipe. Maybe you can try setting "qos=true"  in the appsink, which will monitor late buffers and ask the decoder to start dropping buffers as the appsink can't keep up with the pace.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">Is this the expected behavior? How can I solve this problem?</div><div class=""><br class=""></div><div class="">Thank you a lot,</div><div class=""><br class=""></div><div class="">Matteo</div><div class=""><br class=""></div></div>
</div></blockquote></div><br class=""></div></body></html>