gst-launch

This is a tool that will construct pipelines based on a command-line syntax.

A simple commandline looks like:

gst-launch filesrc location=hello.mp3 ! mad ! osssink
    

A more complex pipeline looks like:

gst-launch filesrc location=redpill.vob ! mpegdemux name=demux \
 demux.audio_00! { ac3parse ! a52dec ! osssink } \
 demux.video_00! { mpeg2dec ! xvideosink }
    

You can also use the parser in you own code. GStreamer provides a function gst_parse_launch () that you can use to construct a pipeline. The following program lets you create an MP3 pipeline using the gst_parse_launch () function:

#include <gst/gst.h>

int
main (int argc, char *argv[])
{
  GstElement *pipeline;
  GstElement *filesrc;
  GError *error = NULL;

  gst_init (&argc, &argv);

  if (argc != 2) {
    g_print ("usage: %s <filename>\n", argv[0]);
    return -1;
  }

  pipeline = gst_parse_launch ("filesrc name=my_filesrc ! mad ! osssink", &error);
  if (!pipeline) {
    g_print ("Parse error: %s\n", error->message);
    exit (1);
  }
  
  filesrc = gst_bin_get_by_name (GST_BIN (pipeline), "my_filesrc");
  g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);

  gst_element_set_state (pipeline, GST_STATE_PLAYING);

  while (gst_bin_iterate (GST_BIN (pipeline)));

  gst_element_set_state (pipeline, GST_STATE_NULL);

  return 0;
}
    

Note how we can retrieve the filesrc element from the constructed bin using the element name.

The gst-launch syntax is processed by a flex/bison parser. This section is intended to provide a full specification of the grammar; any deviations from this specification is considered a bug.