X-Git-Url: https://git.slaskete.net/python-gstreamer-examples/blobdiff_plain/cff7d2b533afd93201d316a24d34137f55714cc0..f85549eda60da52c7de415185aeaf2f937ecaae4:/example5.py diff --git a/example5.py b/example5.py index f2aa4ea..b775398 100755 --- a/example5.py +++ b/example5.py @@ -8,7 +8,7 @@ gi.require_version('Gst', '1.0') gi.require_version('GstVideo', '1.0') from gi.repository import Gtk, Gst, GdkX11, GstVideo -stream1="http://192.168.0.90/video/mjpg.cgi" +stream1="rtmp://matuku.hig.no/live/planet.stream" class Main: def __init__(self): @@ -52,17 +52,25 @@ class Main: self.src1dec = Gst.ElementFactory.make("decodebin", "src1dec") # src2 - self.src2 = Gst.ElementFactory.make("v4l2src", "src2") - self.src2.set_property("device", "/dev/video1") + self.src2 = Gst.ElementFactory.make("videotestsrc", "src2") + self.src2.set_property("pattern", "ball") self.src2caps = Gst.ElementFactory.make("capsfilter", "src2caps") - self.src2caps.set_property("caps", jpegcaps) + self.src2caps.set_property("caps", xrawcaps) self.src2dec = Gst.ElementFactory.make("decodebin", "src2dec") # src3 - self.src3 = Gst.ElementFactory.make("videotestsrc", "src3") - self.src3caps = Gst.ElementFactory.make("capsfilter", "src3caps") - self.src3caps.set_property("caps", xrawcaps) + self.src3 = Gst.ElementFactory.make("rtmpsrc", "src3") + self.src3.set_property("location", stream1) +# self.src3caps = Gst.ElementFactory.make("capsfilter", "src3caps") +# self.src3caps.set_property("caps", xrawcaps) self.src3dec = Gst.ElementFactory.make("decodebin", "src3dec") + self.src3crop = Gst.ElementFactory.make("aspectratiocrop", "src3crop") + self.src3crop.set_property("aspect-ratio", Gst.Fraction(16, 9)) + self.src3crop.set_property("async-handling", True) + self.src3croppad = self.src3crop.get_static_pad("sink") + self.src3scale = Gst.ElementFactory.make("videoscale") + self.src3scalecaps = Gst.ElementFactory.make("capsfilter", "src3scalecaps") + self.src3scalecaps.set_property("caps", Gst.Caps.from_string("width=1280,height=720")) # Video mix self.videomix = Gst.ElementFactory.make("videomixer", "videomix") @@ -81,17 +89,19 @@ class Main: self.pipeline.add(self.src1) self.pipeline.add(self.src1caps) self.pipeline.add(self.src1dec) - self.src1dec.connect("pad-added", self.OnPadAdded, self.src1pad) + self.src1dec.connect("pad-added", self.OnPadAdded, self.src1pad, self.videomix) self.pipeline.add(self.src2) self.pipeline.add(self.src2caps) self.pipeline.add(self.src2dec) - self.src2dec.connect("pad-added", self.OnPadAdded, self.src2pad) + self.src2dec.connect("pad-added", self.OnPadAdded, self.src2pad, self.videomix) self.pipeline.add(self.src3) - self.pipeline.add(self.src3caps) +# self.pipeline.add(self.src3caps) self.pipeline.add(self.src3dec) - self.src3dec.connect("pad-added", self.OnPadAdded, self.src3pad) + self.src3dec.connect("pad-added", self.OnPadAdded, self.src3croppad, self.src3scale) + self.pipeline.add(self.src3scale) + self.pipeline.add(self.src3scalecaps) self.pipeline.add(self.videomix) self.pipeline.add(self.videosink) @@ -109,10 +119,18 @@ class Main: if not self.src2caps.link(self.src2dec): print("Failed to link src2caps to src2dec") - if not self.src3.link(self.src3caps): - print("Failed to link src3 to src3caps") - if not self.src3caps.link(self.src3dec): - print("Failed to link src3caps to src3dec") +# if not self.src3.link(self.src3caps): +# print("Failed to link src3 to src3caps") + if not self.src3.link(self.src3dec): + print("Failed to link src3 to src3dec") + if not self.src3scale.link(self.src3scalecaps): + print("Failed to link src3scale to src3scalecaps") + if not self.src3scalecaps.link(self.src3crop): + print("Failed to link src3scalecaps to src3crop") + if not self.src3crop.link(self.src3cropcaps): + print("Failed to link src3crop to src3cropcaps") + if not self.src3cropcaps.link(self.videomix): + print("Failed to link src3cropcaps to videomix") # Set up a bus to our pipeline to get notified when the video is ready self.bus = self.pipeline.get_bus() @@ -140,10 +158,10 @@ class Main: print("prepare-window-handle") message.src.set_window_handle(self.win_id) - def OnPadAdded(self, element, pad, sink): - print("Dynamic pad added") - print(pad.link(sink)) - print(element.link(self.videomix)) + def OnPadAdded(self, element, pad, sink, target): + print("Dynamic pad for " + element.name + " added, linking to " + target.name) + pad.link(sink) + element.link(target) def SetInput1(self, widget): print("Switch to input 1")