aboutsummaryrefslogtreecommitdiff
path: root/voctocore/videomix.py
blob: 895a25fa0a7271c9cf2039cd0f375b6378ad2368 (plain)
  1. import sys, inspect
  2. from pprint import pprint
  3. from gi.repository import GLib, Gst
  4. class Videomix:
  5. decoder = []
  6. mixerpads = []
  7. def __init__(self):
  8. self.pipeline = Gst.Pipeline()
  9. self.videomixer = Gst.ElementFactory.make('videomixer', 'videomixer')
  10. self.pipeline.add(self.videomixer)
  11. for uri in ("http://video.blendertestbuilds.de/download.blender.org/ED/ED_1280.avi", "http://download.blender.org/durian/trailer/sintel_trailer-720p.mp4",):
  12. decoder = Gst.ElementFactory.make('uridecodebin', 'uridecoder('+uri+')')
  13. decoder.set_property("uri", uri)
  14. decoder.connect("pad-added", self.OnDynamicPad)
  15. self.pipeline.add(decoder)
  16. self.decoder.append(decoder)
  17. self.monitorvideosink = Gst.ElementFactory.make('autovideosink', 'monitorvideosink')
  18. self.pipeline.add(self.monitorvideosink)
  19. self.videomixer.link(self.monitorvideosink)
  20. self.monitoraudiosink = Gst.ElementFactory.make('autoaudiosink', 'monitoraudiosink')
  21. self.pipeline.add(self.monitoraudiosink)
  22. self.pipeline.set_state(Gst.State.PLAYING)
  23. GLib.io_add_watch(sys.stdin, GLib.IO_IN, self.Input)
  24. def Input(self, fd, condition):
  25. if condition == GLib.IO_IN:
  26. char = fd.readline()
  27. try:
  28. i = int(char.rstrip())
  29. print("settinh pad {0} to alpha=1".format(i))
  30. self.mixerpads[i].set_property('alpha', 1)
  31. for idx, pad in enumerate(self.mixerpads):
  32. if idx != i:
  33. print("settinh pad {0} to alpha=0".format(idx))
  34. pad.set_property('alpha', 0)
  35. except:
  36. pass
  37. return True
  38. else:
  39. return False
  40. def OnDynamicPad(self, uridecodebin, src_pad):
  41. caps = src_pad.query_caps(None).to_string()
  42. srcname = uridecodebin.get_name()
  43. print("{0}-source of {1} online".format(caps.split(',')[0], srcname))
  44. if caps.startswith('audio/'):
  45. sinkpad = self.monitoraudiosink.get_static_pad("sink")
  46. # link the first audio-stream and be done
  47. if not sinkpad.is_linked():
  48. src_pad.link(sinkpad)
  49. else:
  50. sinkpad = Gst.Element.get_request_pad(self.videomixer, "sink_%u")
  51. src_pad.link(sinkpad)
  52. self.mixerpads.append(sinkpad)
  53. print('add', sinkpad)
  54. sinkpad.set_property('alpha', 0.7)