diff options
author | MaZderMind <github@mazdermind.de> | 2015-05-10 23:52:31 +0200 |
---|---|---|
committer | MaZderMind <github@mazdermind.de> | 2015-05-10 23:52:31 +0200 |
commit | 10058b623dee99ed54421ff204b51adcc9a379d0 (patch) | |
tree | ea58d8bfb7eb4e7f667e7c8a25ce0fc40e302537 /voctocore/lib/video/mix.py | |
parent | e2602d0aecefccd10fbe1a0cce13bb9f68e60830 (diff) |
implement side-by-side-equal composition
Diffstat (limited to 'voctocore/lib/video/mix.py')
-rw-r--r-- | voctocore/lib/video/mix.py | 94 |
1 files changed, 88 insertions, 6 deletions
diff --git a/voctocore/lib/video/mix.py b/voctocore/lib/video/mix.py index a9e1513..bcac7d2 100644 --- a/voctocore/lib/video/mix.py +++ b/voctocore/lib/video/mix.py @@ -5,8 +5,9 @@ from enum import Enum from lib.config import Config -class ComposteModes(Enum): +class CompositeModes(Enum): fullscreen = 0 + side_by_side_equal = 1 class VideoMix(object): log = logging.getLogger('VideoMix') @@ -16,7 +17,7 @@ class VideoMix(object): caps = None names = [] - compositeMode = ComposteModes.fullscreen + compositeMode = CompositeModes.fullscreen sourceA = 0 sourceB = 1 @@ -58,15 +59,21 @@ class VideoMix(object): self.mixingPipeline.set_state(Gst.State.PLAYING) def updateMixerState(self): - if self.compositeMode == ComposteModes.fullscreen: + if self.compositeMode == CompositeModes.fullscreen: self.updateMixerStateFullscreen() + if self.compositeMode == CompositeModes.side_by_side_equal: + self.updateMixerStateSideBySideEqual() + def updateMixerStateFullscreen(self): self.log.info('Updating Mixer-State for Fullscreen-Composition') + + noScaleCaps = Gst.Caps.from_string('video/x-raw') + for idx, name in enumerate(self.names): alpha = int(idx == self.sourceA) - self.log.debug('Setting Mixerpad %u to x/y=0 and alpha=%u', idx, alpha) + self.log.debug('Setting Mixerpad %u to x/y=0 and alpha=%0.2f', idx, alpha) mixerpad = self.mixingPipeline.get_by_name('mix').get_static_pad('sink_%u' % idx) mixerpad.set_property('alpha', alpha ) mixerpad.set_property('xpos', 0) @@ -74,12 +81,87 @@ class VideoMix(object): self.log.debug('Resetting Scaler %u to non-scaling', idx) capsfilter = self.mixingPipeline.get_by_name('caps_%u' % idx) - capsfilter.set_property('caps', Gst.Caps.from_string(self.caps)) + capsfilter.set_property('caps', noScaleCaps) + + def getInputVideoSize(self): + caps = Gst.Caps.from_string(self.caps) + struct = caps.get_structure(0) + _, width = struct.get_int('width') + _, height = struct.get_int('height') + + return width, height + + def updateMixerStateSideBySideEqual(self): + self.log.info('Updating Mixer-State for Side-by-side-Equal-Composition') + + width, height = self.getInputVideoSize() + gutter = int(width / 100) + + self.log.debug('Video-Size parsed as %u/%u, Gutter calculated to %upx', width, height, gutter) + + targetWidth = int((width - gutter) / 2) + targetHeight = int(targetWidth / width * height) + + ycenter = (height - targetHeight) / 2 + xa = 0 + xb = width - targetWidth + + scaleCaps = Gst.Caps.from_string('video/x-raw,width=%u,height=%u' % (targetWidth, targetHeight)) + noScaleCaps = Gst.Caps.from_string('video/x-raw') + + for idx, name in enumerate(self.names): + mixerpad = self.mixingPipeline.get_by_name('mix').get_static_pad('sink_%u' % idx) + + if idx == self.sourceA: + x = xa + y = ycenter + caps = scaleCaps + alpha = 1 + + self.log.debug('Setting Mixerpad %u to x/y=%u/%u and alpha=%0.2f', idx, x, y, alpha) + self.log.debug('Setting Scaler %u to %u/%u', idx, targetWidth, targetHeight) + + elif idx == self.sourceB: + x = xb + y = ycenter + caps = scaleCaps + alpha = 1 + + self.log.debug('Setting Mixerpad %u to x/y=%u/%u and alpha=%0.2f', idx, x, y, alpha) + self.log.debug('Setting Scaler %u to %u/%u', idx, targetWidth, targetHeight) + + else: + x = 0 + y = 0 + caps = noScaleCaps + alpha = 0 + + self.log.debug('Setting Mixerpad %u to x/y=%u/%u and alpha=%0.2f', idx, x, y, alpha) + self.log.debug('Resetting Scaler %u to non-scaling', idx) + + mixerpad.set_property('alpha', alpha) + mixerpad.set_property('xpos', x) + mixerpad.set_property('ypos', y) + + capsfilter = self.mixingPipeline.get_by_name('caps_%u' % idx) + capsfilter.set_property('caps', caps) def setVideoA(self, source): + # swap if required + if self.sourceB == source: + self.sourceB = self.sourceA + self.sourceA = source self.updateMixerState() def setVideoB(self, source): - self.sourceN = source + # swap if required + if self.sourceA == source: + self.sourceA = self.sourceB + + self.sourceB = source + self.updateMixerState() + + def setCompositeMode(self, mode): + self.compositeMode = mode self.updateMixerState() |