# Reducing latency when capturing and displaying an RTSP stream

**URL:** <https://discourse.processing.org/t/reducing-latency-when-capturing-and-displaying-an-rtsp-stream/26531>\
**Category:** Libraries\
**Created:** [December 27, 2020, 11:37am UTC](https://discourse.processing.org/t/reducing-latency-when-capturing-and-displaying-an-rtsp-stream/26531 "2020-12-27T11:37:44Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [July 12, 2021, 10:26am UTC](https://discourse.processing.org/t/reducing-latency-when-capturing-and-displaying-an-rtsp-stream/26531/3 "2021-07-12T10:26:51Z")

</div>

> [@angelofarina](#):
>
> Only problem is the terrible 3-second latency. Which comes definitely from Processing …  
> So Processing is doing some large buffering of the incoming RTSP stream.

No it isn’t! Only just seen this post. The buffering comes from GStreamer defaults. For some reason I can’t get the Capture `pipeline:` url to work with an rtsp pipeline at first attempt - I think there’s a fix missing in the released Video library at the moment that would allow this.

However, it’s possible to set the latency on the `rtspsrc` inside the Movie’s PlayBin. This would be a little easier if Video had a recent version of our bindings, but this should work -

```java
import processing.video.*;
import org.freedesktop.gstreamer.*;

Movie movie;

void setup() {
  size(2048, 1024, P2D);
  Movie.supportedProtocols[0] = "rtsp";
  println(Movie.supportedProtocols[0]);
  try {
    movie = new Movie(this, "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");
    movie.playbin.connect(new ElementAdded());
    movie.play();
  } 
  catch (Exception e) {
    println(e);
  }
}

void movieEvent(Movie m) {
  m.read();
}

void draw() {
  background(0);
  image(movie, 0, 0, width, height);
}

class ElementAdded implements Bin.ELEMENT_ADDED {
   public void elementAdded(Bin bin, Element element) {
     println("Element added : " + element);
     ElementFactory factory = element.getFactory();
     if (factory == null) {
        return;
     }
     if (element instanceof Bin) {
       ((Bin) element).connect(this); 
     }
     if ("rtspsrc".equals(factory.getName())) {
        println("Setting latency on " + element);
        element.set("latency", 100); 
     }
  }
}

```

Obviously, keep using PraxisLIVE instead though - the integration with GStreamer and Processing is better! 😃

---

_[View the full topic](https://discourse.processing.org/t/reducing-latency-when-capturing-and-displaying-an-rtsp-stream/26531)._
