[ CCode ( returns_floating_reference = true ) ]
public static Element? make (string factoryname, string? name = null)

Create a new element of the type defined by the given element factory.

If name is null, then the element will receive a guaranteed unique name, consisting of the element factory name and a number. If name is given, it will be given the name supplied.

Example: GStreamer concepts:

// See
// for a detailed description

public static int main (string[] args) {

// Initialize GStreamer:
Gst.init (ref args);

// Create the elements:
Gst.Element source = Gst.ElementFactory.make ("videotestsrc", "source");
Gst.Element sink = Gst.ElementFactory.make ("autovideosink", "sink");

// Create the empty pipeline:
Gst.Pipeline pipeline = new Gst.Pipeline ("test-pipeline");

if (source == null || sink == null || pipeline == null) {
stderr.puts ("Not all elements could be created.\n");
return -1;

// Build the pipeline:
pipeline.add_many (source, sink);

if ( (sink) != true) {
stderr.puts ("Elements could not be linked.\n");
return -1;

// Modify the source's properties:
source.set ("pattern", 0);

// Start playing:
Gst.StateChangeReturn ret = pipeline.set_state (Gst.State.PLAYING);
if (ret == Gst.StateChangeReturn.FAILURE) {
stderr.puts ("Unable to set the pipeline to the playing state.\n");
return -1;

// Wait until error or EOS:
Gst.Bus bus = pipeline.get_bus ();
Gst.Message msg = bus.timed_pop_filtered (Gst.CLOCK_TIME_NONE, Gst.MessageType.ERROR | Gst.MessageType.EOS);

// Parse message:
if (msg != null) {
switch (msg.type) {
case Gst.MessageType.ERROR:
GLib.Error err;
string debug_info;

msg.parse_error (out err, out debug_info);
stderr.printf ("Error received from element %s: %s\n",, err.message);
stderr.printf ("Debugging information: %s\n", (debug_info != null)? debug_info : "none");

case Gst.MessageType.EOS:
print ("End-Of-Stream reached.\n");

// We should not reach here because we only asked for ERRORs and EOS:
assert_not_reached ();

// Free resources:
pipeline.set_state (Gst.State.NULL);

return 0;

valac --pkg gstreamer-1.0 concepts.vala



a named factory to instantiate


name of new element, or null to automatically create a unique name


new Element or null if unable to create element