Embedding a pipeline (programmatic construction)¶
A gst-launch-1.0 string is the fastest way to try a pipeline, but an
application that embeds these elements builds the graph in code instead — so it
can set properties from config, read metadata off a pad, react to bus messages,
and change state at runtime. The construction is plain core-GStreamer API and is
identical whether the elements are host-only (nvmmtracker) or Jetson
(nvmminfer); only the factory names and properties differ from the demo below.
The worked example is examples/programmatic_pipeline.cpp.
It is core-GStreamer only (videotestsrc → capsfilter → queue → identity →
fakesink), so it builds and runs everywhere and is exercised in CI as a meson
test. The six steps are the whole pattern:
- Make each element by its registered factory name with
gst_element_factory_make(the same names you would type in a launch string), and agst_pipeline_newto hold them. - Configure with
g_object_set— this is whereengine-file,conf-threshold,leaky, and the rest go, by property name. - Add every element to the bin (
gst_bin_add_many) and link them in order (gst_element_link_many); check the link return, it stops at the first pair that fails to negotiate caps. - Read results off a pad with
gst_pad_add_probe— the example counts buffers; a real graph readsGstNvmmDetMeta/GstNvmmTrackMetaoff the same kind of probe. - Watch the bus (
gst_bus_add_watch) so EOS and ERROR end the run instead of blocking forever. - Run —
gst_element_set_state(PLAYING), drive aGMainLoop, then tear down toNULL.
Turning it into an inference graph¶
Swap the core elements for the real ones — the surrounding code (steps 3–6) does not change:
videotestsrc→ your source, plusnvvidconvintovideo/x-raw(memory:NVMM), format=NV12(the capsnvmminferexpects).identity→nvmminfer(setengine-file), optionally followed bynvmmtracker/nvmmfusekf.fakesink→ your sink (encoder +filesink/udpsink, or anappsinkyou pull metadata from).- Put a
queuebetween the heavy stages for pipeline parallelism, and aqueue leaky=2 max-size-buffers=2at a live source for freshest-frame behaviour — see the tracker pipeline.
The element must be on GST_PLUGIN_PATH for gst_element_factory_make to
resolve it, exactly as for gst-launch-1.0.