Skip to content

Troubleshooting GStreamer Element Link Failures

Common causes of element-link failures, including incompatible caps, missing pads, and pipeline timing.

This English edition preserves the original commands, configuration fragments, and diagrams so the steps can be reproduced directly.

Commands and configuration

GstElement *videoconvert = gst_element_factory_make("videoconvert", "videoconvert");
GstElement *gamma = gst_element_factory_make("gamma", "gamma");

if (!videoconvert || !gamma) {
    GST_ERROR("Failed to create elements");
    return;
}

# 同时不要忘记将元素添加到bin中:
gst_bin_add_many(GST_BIN(_pipeline), _source, _tee, decoderQueue, _decoderValve, _videobalance, _videoconvert, recorderQueue, _recorderValve, nullptr);
c复制代码GstCaps *src_caps = gst_pad_query_caps(gst_element_get_static_pad(videoconvert, "src"), NULL);
GstCaps *sink_caps = gst_pad_query_caps(gst_element_get_static_pad(gamma, "sink"), NULL);

// 检查 capabilities 是否兼容
if (!gst_caps_can_intersect(src_caps, sink_caps)) {
    GST_ERROR("Caps of src and sink are incompatible");
}
bash


复制代码
export GST_DEBUG=*:4  # 设置调试级别为 4
c复制代码GstCaps *filter_caps = gst_caps_new_simple("video/x-raw",
                                           "format", G_TYPE_STRING, "RGBA",
                                           "width", G_TYPE_INT, 640,
                                           "height", G_TYPE_INT, 480, NULL);
GstElement *capsfilter = gst_element_factory_make("capsfilter", "capsfilter");

g_object_set(capsfilter, "caps", filter_caps, NULL);

gst_element_link(videoconvert, capsfilter);
gst_element_link(capsfilter, gamma);
c复制代码GstElement *videoconvert, *gamma, *capsfilter;
GstCaps *filter_caps;
GstPad *videoconvert_src, *gamma_sink;

// 创建元素
videoconvert = gst_element_factory_make("videoconvert", "videoconvert");
gamma = gst_element_factory_make("gamma", "gamma");
capsfilter = gst_element_factory_make("capsfilter", "capsfilter");

if (!videoconvert || !gamma || !capsfilter) {
    GST_ERROR("Failed to create elements");
    return;
}

// 创建 capsfilter 的 capabilities
filter_caps = gst_caps_new_simple("video/x-raw",
                                  "format", G_TYPE_STRING, "RGBA",
                                  "width", G_TYPE_INT, 640,
                                  "height", G_TYPE_INT, 480, NULL);
g_object_set(capsfilter, "caps", filter_caps, NULL);

// 添加到管道
gst_bin_add_many(GST_BIN(pipeline), videoconvert, capsfilter, gamma, NULL);

// 连接元素
if (!gst_element_link(videoconvert, capsfilter)) {
    GST_ERROR("Failed to link videoconvert to capsfilter");
    return;
}

if (!gst_element_link(capsfilter, gamma)) {
    GST_ERROR("Failed to link capsfilter to gamma");
    return;
}

Notes

Use these examples as a starting point and adjust versions, device names, codecs, and network addresses for the target platform.