Skip to content
systemcoding.dev
Media

Build Your First Pipeline With gst-launch-1.0

Write, run and debug your first GStreamer pipeline with gst-launch-1.0: sources, converters, sinks, properties, caps filters and the -v and -e flags.

7 min read
Summarize in AI
Flat illustration of a CPU core with its cache levels and main memory, with the FFmpeg, GStreamer and AMD logos.

gst-launch-1.0 is the quickest way to learn GStreamer, because you can build a working media pipeline in one line of shell and change it in seconds. It is a prototyping tool: it parses a textual description, builds the pipeline, runs it and prints what happens. This post builds three pipelines of growing size, explains every symbol in them, and teaches the two flags, -v and -e, that you will use every day. Commands are for GStreamer 1.26 on Linux; the same syntax works on macOS and Windows with different sink names.

Check that GStreamer is installed

The tool ships in the GStreamer tools package, and the plugins come in separate packages. On Debian or Ubuntu the packages are gstreamer1.0-tools, gstreamer1.0-plugins-base, gstreamer1.0-plugins-good and friends, which a companion post explains. Confirm the install:

Shell
gst-launch-1.0 --version
Text
gst-launch-1.0 version 1.26.2
GStreamer 1.26.2
https://launchpad.net/distros/ubuntu/+source/gstreamer1.0

The exact patch number will differ on your machine. Anything in the 1.x series uses the -1.0 suffix on every tool name, which is why the command is not plain gst-launch.

The syntax in one paragraph

A pipeline description is a list of elements separated by !. Data flows left to right: the output of one element becomes the input of the next. An element can be followed by properties as name=value pairs, separated by spaces. A quoted string between two ! is a caps filter that restricts the format. That is the entire grammar for linear pipelines.

Pipeline 1: test pattern to a window

Shell
gst-launch-1.0 videotestsrc ! videoconvert ! autovideosink

Three elements. videotestsrc generates colour bars. videoconvert converts between raw pixel formats, which is not needed on every machine but costs almost nothing when the formats already match, so it is a habit worth keeping before a video sink. autovideosink chooses a sink that fits your desktop.

The terminal prints the state changes and then runs until you press Ctrl+C:

Text
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
^Chandling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 0:00:04.113828432
Setting pipeline to NULL ...
Freeing pipeline ...

Read those lines, because they explain the state machine. PAUSED means elements are created and linked. PREROLLING means the sinks are waiting for their first buffer, so the window can show a frame before time starts. PLAYING means data flows against the clock. The elapsed time differs on every run.

Properties change behaviour

Add properties directly after the element name:

Shell
gst-launch-1.0 videotestsrc pattern=ball num-buffers=300 is-live=false ! videoconvert ! autovideosink

pattern=ball selects a moving ball instead of colour bars, and num-buffers=300 ends the stream after 300 frames, which is ten seconds at the default 30 frames per second. When the source finishes it sends end-of-stream, the sink sees it, and the tool exits by itself with "Got EOS from element". gst-inspect-1.0 videotestsrc lists every property with its allowed values.

Enumeration properties accept either the nick or the number. If you type an invalid value, gst-launch-1.0 stops with a message like this:

Text
WARNING: erroneous pipeline: no property "patern" in element "videotestsrc0"

That message includes the auto-generated element name, videotestsrc0. Giving an element your own name with name=src helps once pipelines get big.

Pipeline 2: set the format with a caps filter

Between two elements, a quoted caps string restricts what may flow:

Shell
gst-launch-1.0 videotestsrc num-buffers=150 ! "video/x-raw,width=640,height=360,framerate=15/1" ! videoconvert ! autovideosink

The source now produces 640x360 at 15 frames per second, because the capsfilter removes every other option from the negotiation. If the source cannot satisfy it, you get not-negotiated. Without the quotes, the shell would split the string at the commas or interpret ! as history expansion in interactive shells, so keep the quotes.

Pipeline 3: audio and video together

A single description can contain several branches. Separate them with a space and no !, and name an element to link to it from elsewhere. For two independent streams, simply write two chains:

Shell
gst-launch-1.0 videotestsrc num-buffers=200 ! videoconvert ! autovideosink audiotestsrc num-buffers=200 samplesperbuffer=1600 ! audioconvert ! autoaudiosink

Both chains run inside the same pipeline and share one clock. audiotestsrc produces a 440 Hz sine tone by default, and samplesperbuffer=1600 makes each buffer 1600 samples, which at the default 44100 Hz rate is about 36 ms of audio. audioconvert is the audio counterpart of videoconvert.

If you need to branch one source into two sinks, use tee, covered in its own post. If a chain must feed a muxer that is declared elsewhere, give the muxer a name and refer to it as mux.:

Shell
gst-launch-1.0 videotestsrc num-buffers=90 ! videoconvert ! x264enc ! h264parse ! mp4mux name=mux ! filesink location=test.mp4 audiotestsrc num-buffers=90 ! audioconvert ! avenc_aac ! aacparse ! mux.

The mux. at the end means "link this chain into the element named mux". The trailing dot is the syntax for referring to an element by name rather than creating one.

The two flags worth memorising

**-v (verbose)** prints the negotiated caps of every pad and every property change. When something does not link, this is the first thing to run:

Shell
gst-launch-1.0 -v videotestsrc num-buffers=1 ! "video/x-raw,width=320,height=240" ! fakesink
Text
/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)progressive
Got EOS from element "pipeline0".

**-e (EOS on interrupt)** matters whenever you write a file. Without it, Ctrl+C kills the pipeline, and a container such as MP4 never gets its index written, so the file will not play. With -e, Ctrl+C sends end-of-stream through the pipeline first, so muxers can finish:

Shell
gst-launch-1.0 -e videotestsrc ! videoconvert ! x264enc ! h264parse ! mp4mux ! filesink location=capture.mp4

Press Ctrl+C after a few seconds and capture.mp4 is a playable file. Run the same line without -e and the file lacks its moov box, a common surprise explained in the MP4 format post.

Reading errors

Three error shapes cover most of your first week:

Text
WARNING: erroneous pipeline: no element "videoconvrt"

The element name is wrong, or its plugin package is not installed. Check it with gst-inspect-1.0 videoconvrt, which fails the same way when the plugin is missing.

Text
ERROR: from element /GstPipeline:pipeline0/GstFileSrc:filesrc0: Resource not found.

The location points at a file that does not exist. The error names the element that failed, and the path in the message is the part of the element tree.

Text
ERROR: pipeline doesn't want to preroll.

Something could not negotiate. Run again with -v and read the caps on the last pad before the failure.

When gst-launch is the wrong tool

gst-launch-1.0 has no error recovery, no dynamic reconfiguration, no way to react to events and a documented warning from the GStreamer project that its syntax is for testing, not for applications. Once the pipeline works, move it into a program with gst_parse_launch, covered in a later post, which accepts the very same string.

Debugging a pipeline that will not start

Three environment variables turn gst-launch-1.0 from a black box into a readable tool. GST_DEBUG sets a log level, either globally with a number or per category with a name. GST_DEBUG=2 prints warnings and errors only, which is usually enough, and GST_DEBUG=4 adds informational messages about linking and negotiation:

Shell
GST_DEBUG=2 gst-launch-1.0 videotestsrc num-buffers=10 ! "video/x-raw,format=NV99" ! fakesink
Text
0:00:00.056112345 12345 0x55d0c8a05a80 WARN              capsfilter gstcapsfilter.c:xxx:gst_capsfilter_prepare_buf:<capsfilter0> Caps filter 'video/x-raw, format=(string)NV99' could not be fixed
ERROR: from element /GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0: Internal data stream error.

The first line shows the timestamp, process id, thread, level, category and the message. Exact numbers and source line differ on every machine. The point is the shape: the category capsfilter tells you which part of GStreamer complained, and you can then raise only that category with GST_DEBUG=capsfilter:5 instead of drowning in output.

GST_DEBUG_DUMP_DOT_DIR is the second variable. Set it to a directory and the tool writes a Graphviz file of the pipeline at each state, which you can render with dot -Tpng. A dedicated post covers it, but even a quick look at the picture shows which element did not link.

GST_PLUGIN_PATH adds a directory to the plugin search path, useful when you build your own element.

A repeatable workflow

When you are building a new pipeline, grow it one element at a time. Start with the source and fakesink, confirm it runs, then insert the next element before the sink. If the pipeline fails after you added element N, then element N or its link to element N-1 is the cause, and you only have one thing to examine. This is faster than writing six elements and then trying to guess which one broke.

Shell
gst-launch-1.0 -v v4l2src num-buffers=30 ! fakesink
gst-launch-1.0 -v v4l2src num-buffers=30 ! videoconvert ! fakesink
gst-launch-1.0 -v v4l2src num-buffers=30 ! videoconvert ! x264enc ! fakesink

Each command is a step. Using fakesink as the last element removes the display and file from the equation, so a failure points at the part you just added.

Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.