Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gi
- gi.require_version('Gst', '1.0')
- from gi.repository import Gst, GLib
- class GstRelay:
- def __init__(self):
- Gst.init(None)
- self.pipeline1 = Gst.parse_launch(
- "videotestsrc pattern=ball is-live=true ! video/x-raw,format=RGB,width=1280,height=720,framerate=240/1 ! videoconvert ! appsink name=sink"
- )
- self.appsink = self.pipeline1.get_by_name("sink")
- self.appsink.set_property("emit-signals", True)
- self.appsink.connect("new-sample", self.on_new_sample)
- self.pipeline2 = Gst.parse_launch(
- "appsrc name=src ! videoconvert ! autovideosink"
- )
- self.appsrc = self.pipeline2.get_by_name("src")
- self.appsrc.set_property("caps", Gst.Caps.from_string("video/x-raw,format=RGB,width=1280,height=720"))
- def on_new_sample(self, sink):
- """Callback when new frame arrives at appsink (Pipeline 1)."""
- sample = sink.emit("pull-sample")
- if not sample:
- return Gst.FlowReturn.ERROR
- buffer = sample.get_buffer()
- self.appsrc.emit("push-buffer", buffer)
- return Gst.FlowReturn.OK
- def start(self):
- """Start both pipelines."""
- self.pipeline1.set_state(Gst.State.PLAYING)
- self.pipeline2.set_state(Gst.State.PLAYING)
- def stop(self):
- """Stop both pipelines."""
- self.pipeline1.set_state(Gst.State.NULL)
- self.pipeline2.set_state(Gst.State.NULL)
- def main():
- gst_relay = GstRelay()
- gst_relay.start()
- loop = GLib.MainLoop()
- try:
- loop.run()
- except KeyboardInterrupt:
- print("Stopping pipelines...")
- gst_relay.stop()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement