GStreamer Elements, Pads, Caps and Bins Explained
Learn the four ideas behind every GStreamer pipeline: elements that process data, pads that connect them, caps that describe formats, and bins that group them.

GStreamer looks intimidating from the outside because every tutorial throws a long pipeline string at you and expects the pieces to make sense. They do make sense once you know four words: element, pad, caps and bin. Everything else in the framework, from playbin to a hand-built encoder chain, is those four ideas combined. This post defines each one, shows it in a command you can type, and explains the failure you will meet when two of them disagree. It targets GStreamer 1.26, the stable series current when this was written, and all names come from the GStreamer core documentation.
Elements: the units of work
An element is one object that does one job. A file reader is an element. An H.264 decoder is an element. A window that shows video is an element. GStreamer ships hundreds, and each is a plugin you can list with gst-inspect-1.0.
Elements fall into three roles, which is the first useful way to read any pipeline:
| Role | Has | Examples |
|---|---|---|
| Source | outputs only | filesrc, v4l2src, audiotestsrc, videotestsrc |
| Filter | inputs and outputs | videoconvert, x264enc, avdec_h264, queue |
| Sink | inputs only | autovideosink, filesink, fakesink, alsasink |
Here is the smallest useful pipeline. It has a source, a filter and a sink, connected with !:
gst-launch-1.0 videotestsrc num-buffers=100 ! videoconvert ! autovideosinkvideotestsrc generates a test pattern, videoconvert translates the pixel format if the display needs a different one, and autovideosink picks a window system sink. num-buffers=100 is a property, a named setting on an element, so the source stops after 100 frames. Every element has properties, and gst-inspect-1.0 videotestsrc lists them with their types and defaults.
Pads: the connection points
An element does not connect to another element directly. It connects through pads, which are the named openings on its edges. A pad that receives data is a sink pad and a pad that sends data is a source pad. The naming trips people up the first time: a sink element has only sink pads, but a filter has both a sink pad (input) and a source pad (output).
Pads have a direction and a name. Most elements have one of each, called sink and src. Some have several, and gst-inspect-1.0 shows them under "Pad Templates":
gst-inspect-1.0 videoconvertAn abridged part of the output looks like this:
Pad Templates:
SINK template: 'sink'
Availability: Always
Capabilities:
video/x-raw
format: { I420, YV12, YUY2, ... }
SRC template: 'src'
Availability: Always
Capabilities:
video/x-raw
format: { I420, YV12, YUY2, ... }The Availability line introduces a distinction you must know. Always pads exist from the moment the element is created. Sometimes pads appear only when the element has looked at the data, as a demuxer does after it has read the file header and found out how many streams there are. Request pads are created on demand, as tee does when you ask for another output branch. Much of the early confusion, including most "my pipeline links in gst-launch but not in C" questions, come from sometimes pads. Linking them in code is done from the pad-added signal, which a later post in this series walks through.
Caps: what flows through a pad
A pad does not carry just any bytes. It carries a specific kind of data, and caps (capabilities) is the description of that kind. Caps are a media type plus a set of fields:
video/x-raw, format=I420, width=1280, height=720, framerate=30/1
audio/x-raw, format=S16LE, rate=48000, channels=2, layout=interleaved
video/x-h264, stream-format=byte-stream, alignment=auvideo/x-raw is uncompressed video, video/x-h264 is compressed H.264, and the fields narrow it down. Two ideas make caps work:
Compatibility check. When you link a source pad to a sink pad, GStreamer intersects their caps. If the intersection is empty, the link fails with "not-negotiated" or "could not link". This is the single most common error for new users: you asked an element for a format the next one cannot take.
Negotiation. Caps on a pad are usually a range, such as
width=[1,32768]. Before data flows, the elements agree on one concrete value for every field. You can force it by writing a caps filter in the pipeline:
gst-launch-1.0 videotestsrc num-buffers=100 ! "video/x-raw,width=640,height=360,framerate=30/1" ! videoconvert ! autovideosinkThe quoted string between two ! is a capsfilter, an identity element whose only job is to restrict the caps that pass. Here it fixes the output of videotestsrc to 640x360 at 30 frames per second. The quotes protect the commas from the shell.
When a pipeline does not link, print the real caps with -v:
gst-launch-1.0 -v videotestsrc num-buffers=1 ! fakesinkSetting pipeline to PAUSED ...
Pipeline is PREROLLING ...
/GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0.GstPad:src: caps = video/x-raw, format=(string)I420, width=(int)320, height=(int)240, framerate=(fraction)30/1, multiview-mode=(string)mono, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressiveThe verbose line shows the negotiated, fully specified caps on that pad: the answer to "what is actually flowing here". The default 320x240 comes from the videotestsrc template defaults.
Bins: groups that act like elements
A bin is an element that contains other elements. It forwards its children's messages upward and drives their state changes, and from outside it looks like one element. A pipeline is the top-level bin: it additionally provides a clock and a bus, and it is what you set to PLAYING.
Bins let you build in layers. playbin is a bin containing a source, a demuxer, decoders and sinks, and it assembles them itself. When you write your own, the C code is short:
#include <gst/gst.h>
int main(int argc, char *argv[])
{
gst_init(&argc, &argv);
GstElement *pipeline = gst_pipeline_new("demo");
GstElement *src = gst_element_factory_make("videotestsrc", "src");
GstElement *convert = gst_element_factory_make("videoconvert", "convert");
GstElement *sink = gst_element_factory_make("fakesink", "sink");
if (!pipeline || !src || !convert || !sink) {
g_printerr("could not create elements\n");
return 1;
}
gst_bin_add_many(GST_BIN(pipeline), src, convert, sink, NULL);
if (!gst_element_link_many(src, convert, sink, NULL)) {
g_printerr("link failed\n");
return 1;
}
g_print("children: %u\n", GST_BIN_NUMCHILDREN(GST_BIN(pipeline)));
gst_object_unref(pipeline);
return 0;
}Compile it with gcc bin_demo.c -o bin_demo $(pkg-config --cflags --libs gstreamer-1.0). The pipeline is a bin, gst_bin_add_many puts the three elements inside it and hands over ownership, and gst_element_link_many connects their always-pads in order, negotiating caps on each link. The output is:
children: 3Because the pipeline owns the children, a single gst_object_unref frees all of them. That ownership rule, a bin takes the reference, is why you do not unref the elements you added.
How the four ideas fit together
Read any pipeline with the same questions. Which elements are sources, filters and sinks? Which pads connect them, and are any of them sometimes or request pads? What caps does each link carry, and could the intersection be empty? Is any group of elements better wrapped in a bin?
A transcoding pipeline from a file shows all four:
gst-launch-1.0 filesrc location=input.mp4 ! qtdemux ! h264parse ! avdec_h264 ! videoconvert ! x264enc ! mp4mux ! filesink location=out.mp4filesrc is the source and filesink the sink. qtdemux has sometimes pads, since it learns the streams from the file header. Between avdec_h264 and x264enc the caps are raw video, and between x264enc and mp4mux they are compressed H.264. The gst-launch-1.0 tool wraps all of it in a top-level pipeline bin for you.
Reading a real pipeline with the four ideas
Take a pipeline you have not seen before and walk it with four questions. Suppose someone gives you this and says it "does not work":
gst-launch-1.0 v4l2src ! x264enc ! mp4mux ! filesink location=cam.mp4Question one: which element is the source, which are filters and which is the sink? v4l2src is the source, x264enc and mp4mux are filters, filesink is the sink. Question two: are any pads sometimes or request pads? mp4mux has request pads for its inputs, which gst-launch-1.0 handles by asking for one when you link. Question three: do the caps intersect on each link? v4l2src offers raw video in whatever format the camera supports, often YUY2 or MJPG, and x264enc accepts only certain raw formats, so a videoconvert is probably missing between them. The message you would see is a not-negotiated error naming the pad of x264enc. Question four: is anything missing from the group? A muxer needs its end-of-stream signal, so the command needs -e, as the previous post in this series explains.
The corrected line is longer, and every addition answers one of the questions:
gst-launch-1.0 -e v4l2src ! videoconvert ! x264enc ! h264parse ! mp4mux ! filesink location=cam.mp4That habit, asking the four questions in order, solves most beginner pipelines faster than searching for the error text.
Caps have three shapes
A pad's caps can be described in three ways, and the difference explains a lot of error messages. Template caps are the broad description in the pad template, with ranges and lists: this is what gst-inspect-1.0 shows. Possible caps are the template narrowed by what the peer element accepts, which GStreamer calculates during a caps query. Negotiated caps are the single fixed value chosen before data flows, and -v prints them.
When a caps filter is placed in the pipeline, it narrows the possible caps, and the negotiation picks a fixed result inside what remains. Fixed caps contain no ranges or lists. If a field is still a range after negotiation, an element will usually pick a default or fail, which is how you get surprising resolutions from cameras that support many modes. Writing width=640,height=360 in a capsfilter makes that field a single value, and the camera mode is chosen to match.
Features are the one extension to caps you will meet. A caps string can carry a feature such as memory:DMABuf or memory:GLMemory, written as video/x-raw(memory:DMABuf). It states that the buffers live in a particular kind of memory, so two elements that agree on the format but not on the memory feature still fail to link. When you see (memory:...) in a failing link, the cure is usually a converter that moves the data to system memory, such as videoconvert, or a matching element on both sides.
Bins and the bus
A bin does one more thing besides containing elements: it collects their messages and forwards them to its parent. Every element can post messages: errors, warnings, state changes, tags and end-of-stream. A bin passes those up, so the top-level pipeline's bus receives them all. An application reads the bus to find out when playback finished or failed, which is why the C examples in this series wait on the bus rather than polling an element.
Messages are the reason bins are more than folders. If a decoder deep inside playbin fails, the error bubbles through the bins to the pipeline's bus, and the application sees one error message with the path of the element that raised it. In a message printed by gst-launch-1.0, that path looks like /GstPipeline:pipeline0/GstPlayBin:playbin0/GstURIDecodeBin:uridecodebin0, and reading it from left to right tells you which nested bin the failing element belongs to.


