Failed to link elements rtpsrc0 and capsfilter0

Hi, gstreamer beginner here. I have an axis camera rstp stream which i want to move into an autovideosink. It works fine with gst-launch,

gst-launch-1.0 -v rtspsrc location=rtsp:// user-id=USER user-pw=PASS latency=100 ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! autovideosink

but when I try to create it with the same elements in Rust, I get the error: Failed to link elements rtpsrc0 and capsfilter0.
Below are the caps and the src. Not sure how to debug this further or continue from here…

let input_caps = gst::Caps::builder("application/x-rtp")
    .field("media", &"video")
    .field("encoding-name", &"H264")
    .field("payload", 96_u32)
    .field("clock-rate", 90000_u32)

let input_capsfilter = gst::ElementFactory::make("capsfilter")
    .property("caps", &input_caps)
    .map_err(|_| anyhow::anyhow!("Failed to create capsfilter element"))?;

let rtsp_src = gst::ElementFactory::make("rtspsrc")
    .property("location", "rtsp://")
    .property("user-id", "root")
    .property("user-pw", "otiv3")
    //.property("add-reference-timestamp-meta", true)
    //.property("rfc7273-sync", true)
    // .property("ntp-sync", true)
    //.property("latency", 100_u32) // ms
    .map_err(|_| anyhow::anyhow!("Failed to create rtspsrc element"))?;


You can’t link rtspsrc and the capsfilter right after creating them, because rtspsrc has so-called “dynamic pads” or “sometimes pads” which don’t yet exist when the element is created, but will only be added once you start the pipeline and it has talked to the RTSP server and figured out how many streams of what types there are etc.

You need to handle the “pad-added” signal and link the elements there.

gst-launch-1.0 will do this kind of magic under the hood for you, but if you write code you have to do it yourself, unless you create the pipeline with gst_parse_launch() (or Rust equivalent).

See Pads and capabilities

You don’t really need the capsfilter here for what it’s worth, rtspsrc should already set proper caps on the source pads it adds.

1 Like