Reducing latency when capturing and displaying an 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 -

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! :smiley:

2 Likes