pythongstreamerpython-gstreamer

How to create gstreamer pipeline in python with a probe


I am trying to write a code that takes image input, writes some text over it, and then sends it to the sink (app, file, or Gtk display).

The code below works in the terminal and through python:

pipeline = Gst.parse_launch(f"videotestsrc ! videoscale ! video/x-raw,width=1920,height=1080 ! autovideosink")

I need a probe here to put some text on the images, so I have converted this in the gi format for manipulating it. The code gives no visual or text output. Is there anything wrong with the code:

pipeline = Gst.Pipeline()

source = Gst.ElementFactory.make("videotestsrc", "video-source")
pipeline.add(source)

scale = Gst.ElementFactory.make("videoscale", "scale")
pipeline.add(scale)

caps = Gst.Caps.from_string("video/x-raw,width=1920,height=1080")
filter = Gst.ElementFactory.make("capsfilter", "filter")
filter.set_property("caps", caps)
pipeline.add(filter)
scale.link(filter)

sink = Gst.ElementFactory.make("autovideosink", "video-sink")
pipeline.add(sink)
filter.link(sink)

loop = GLib.MainLoop()
pipeline.set_state(Gst.State.PLAYING)

try:
    loop.run()
except Exception as e:
    print(e)

pipeline.set_state(Gst.State.NULL)

Solution

  • You didn't link your videotestsrc to your videoscale element. In other words, you forgot

    source.link(scale)