From dfbb8a4090a960e463ce0a3a619b9bc408d8c95e Mon Sep 17 00:00:00 2001 From: Matthew Clark Date: Tue, 27 Nov 2018 15:29:47 +0000 Subject: [PATCH] Support for Kinesis Video --- brave/outputs/__init__.py | 3 ++ brave/outputs/kvs.py | 62 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 brave/outputs/kvs.py diff --git a/brave/outputs/__init__.py b/brave/outputs/__init__.py index fa1fc67..8dadbff 100644 --- a/brave/outputs/__init__.py +++ b/brave/outputs/__init__.py @@ -4,6 +4,7 @@ from brave.outputs.image import ImageOutput from brave.outputs.file import FileOutput from brave.outputs.webrtc import WebRTCOutput +from brave.outputs.kvs import KvsOutput from brave.abstract_collection import AbstractCollection import brave.exceptions @@ -26,6 +27,8 @@ def add(self, **args): output = FileOutput(**args, collection=self) elif args['type'] == 'webrtc': output = WebRTCOutput(**args, collection=self) + elif args['type'] == 'kvs': + output = KvsOutput(**args, collection=self) else: raise brave.exceptions.InvalidConfiguration("Invalid output type '%s'" % args['type']) diff --git a/brave/outputs/kvs.py b/brave/outputs/kvs.py new file mode 100644 index 0000000..616aceb --- /dev/null +++ b/brave/outputs/kvs.py @@ -0,0 +1,62 @@ +from brave.outputs.output import Output +import brave.config as config +import brave.exceptions +import os + + +class KvsOutput(Output): + ''' + For outputting to AWS's Kinesis Video Stream + ''' + + def permitted_props(self): + return { + **super().permitted_props(), + 'width': { + 'type': 'int', + 'default': 640, + }, + 'height': { + 'type': 'int', + 'default': 360 + }, + 'stream_name': { + 'type': 'str' + } + } + + def create_elements(self): + if not config.enable_video(): + return + + access_key = os.environ['AWS_ACCESS_KEY_ID'] + secret_key = os.environ['AWS_SECRET_ACCESS_KEY'] + if not access_key: + raise brave.exceptions.InvalidConfiguration('Missing AWS_ACCESS_KEY_ID environemnt variable') + if not secret_key: + raise brave.exceptions.InvalidConfiguration('Missing AWS_SECRET_ACCESS_KEY environemnt variable') + + self._create_initial_multiqueue() + + video_caps = 'video/x-raw,format=I420,width=%d,height=%d,pixel-aspect-ratio=1/1,framerate=30/1' % \ + (self.props['width'], self.props['height']) + + pipeline_string = ('intervideosrc name=intervideosrc ! videoconvert ! videoscale ! ' + + video_caps + + # 'video/x-raw,format=I420,width=640,height=480,framerate=30/1 ! ' + ' ! x264enc bframes=0 key-int-max=45 bitrate=500 ! ' + 'video/x-h264,stream-format=avc,alignment=au ! ' + 'kvssink name=kvssink') + + if not self.create_pipeline_from_string(pipeline_string): + self.logger.error('TEMP cannot create pipeline from string:%s' % pipeline_string) + return False + + kvssink = self.pipeline.get_by_name('kvssink') + kvssink.set_property('access-key', access_key) + kvssink.set_property('secret-key', secret_key) + kvssink.set_property('stream-name', self.props['stream_name']) + + self.intervideosrc = self.pipeline.get_by_name('intervideosrc') + self.intervideosrc_src_pad = self.intervideosrc.get_static_pad('src') + self.create_intervideosink_and_connections()