summaryrefslogtreecommitdiff
path: root/voctocore/videomix.py
blob: e67a7b1567b5a1c318cc15c216099eb5f2893f6d (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. # create audio and video mixer
  10. mixerbin = self.createMixer()
  11. self.pipeline.add(mixerbin)
  12. # create camera sources
  13. for camberabin in self.createDummyCamSources():
  14. # link camerasource to the mixers
  15. self.pipeline.add(camberabin)
  16. camberabin.get_by_name('video_src').link(self.pipeline.get_by_name('livevideo'))
  17. camberabin.get_by_name('audio_src').link(self.pipeline.get_by_name('liveaudio'))
  18. # demonstrate some control
  19. liveaudio = self.pipeline.get_by_name('liveaudio')
  20. liveaudio.set_property('active-pad', liveaudio.get_static_pad('sink_0'))
  21. livevideo = self.pipeline.get_by_name('livevideo')
  22. pad = livevideo.get_static_pad('sink_1')
  23. pad.set_property('alpha', 0.5)
  24. self.pipeline.set_state(Gst.State.PLAYING)
  25. def createMixer(self):
  26. return Gst.parse_bin_from_description("""
  27. videomixer name=livevideo ! autovideosink
  28. input-selector name=liveaudio ! autoaudiosink
  29. """, False)
  30. def createDummyCamSources(self):
  31. uris = ('file:///home/peter/122.mp4', 'file:///home/peter/10025.mp4',)
  32. for idx, uri in enumerate(uris):
  33. # create a bin for camera input
  34. camberabin = Gst.parse_bin_from_description("""
  35. uridecodebin name=input
  36. input. ! videoconvert ! videoscale ! videorate ! video/x-raw,width=1024,height=576,framerate=25/1 ! identity name=video_src
  37. input. ! audioconvert name=audio_src
  38. """, False)
  39. # configure camera input
  40. camberabin.get_by_name('input').set_property('uri', uri)
  41. # pass bin upstream
  42. yield camberabin
  43. def createCamSources(self):
  44. for cam in range(2):
  45. # create a bin for camera input
  46. camberabin = Gst.parse_bin_from_description("""
  47. decklinksrc name=input input=sdi input-mode=1080p25
  48. input. ! videoconvert ! videoscale ! videorate ! video/x-raw,width=1920,height=1080,framerate=25/1 ! identity name=video_src
  49. input. ! audioconvert name=audio_src
  50. """, False)
  51. # configure camera input
  52. camberabin.get_by_name('input').set_property('subdevice', cam)
  53. # pass bin upstream
  54. yield camberabin