diff options
author | Christian Pointner <equinox@spreadspace.org> | 2018-01-27 02:38:30 +0100 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2018-01-27 02:38:30 +0100 |
commit | 151a4cb2baede38bdc3997786e2c103fa437c0cb (patch) | |
tree | db753799aa6bc841d05c604d854fa233aa50a6fd | |
parent | added audio/video encoder and muxer (diff) |
cleanup
-rwxr-xr-x | src/flufigut.py | 156 | ||||
-rw-r--r-- | templates/flumotion/default/flv-mux.xml | 2 | ||||
-rw-r--r-- | templates/flumotion/default/mkv-mux.xml | 2 | ||||
-rw-r--r-- | templates/flumotion/default/mpegts-mux.xml | 2 | ||||
-rw-r--r-- | templates/flumotion/default/ogg-mux.xml | 2 | ||||
-rw-r--r-- | templates/flumotion/default/webm-mux.xml | 2 |
6 files changed, 61 insertions, 105 deletions
diff --git a/src/flufigut.py b/src/flufigut.py index c533a08..7901e9a 100755 --- a/src/flufigut.py +++ b/src/flufigut.py @@ -86,39 +86,33 @@ class Planet: def __init__(self): self.atmosphere = {} self.flow = {} - self._workers = {} - self._components = {} # # inputs - def __set_input_properties(self, name, props, globals): + def __set_input_properties(self, comp_name, props, globals): for prop in props.keys(): if prop == 'resolution': - self.flow['inputs'][name]['properties']['width'] = globals['resolutions'][props[prop]]['width'] - self.flow['inputs'][name]['properties']['height'] = globals['resolutions'][props[prop]]['height'] - self.flow['inputs'][name]['properties']['framerate'] = globals['resolutions'][props[prop]]['rate'] + self.flow['inputs'][comp_name]['properties']['width'] = globals['resolutions'][props[prop]]['width'] + self.flow['inputs'][comp_name]['properties']['height'] = globals['resolutions'][props[prop]]['height'] + self.flow['inputs'][comp_name]['properties']['framerate'] = globals['resolutions'][props[prop]]['rate'] else: - self.flow['inputs'][name]['properties'][prop] = props[prop] + self.flow['inputs'][comp_name]['properties'][prop] = props[prop] def _generate_inputs(self, inputs, globals): self.flow['inputs'] = {} master_cnt = 0 for source, input in inputs.items(): - name = 'input-%s' % source - if name not in self._components: - self._components[name] = -1 - else: - self._components[name] = 1 - self.flow['inputs'][name] = { + comp_name = 'input-%s' % source + self.flow['inputs'][comp_name] = { 'type': input['type'], 'desc': "capture raw data from %s" % (source), - 'worker': name, + 'worker': None, 'master': input['master'], 'properties': {}, } if input['master']: master_cnt += 1 - self.__set_input_properties(name, input['properties'], globals) + self.__set_input_properties(comp_name, input['properties'], globals) if master_cnt == 0: raise exception("You have not configured any master clock device!") @@ -133,24 +127,19 @@ class Planet: if 'samplerate' not in globals['formats'][format]: return - samplerate = globals['formats'][format]['samplerate'] - if samplerate == input_samplerate: + target_samplerate = globals['formats'][format]['samplerate'] + if target_samplerate == input_samplerate: return - comp_name = 'resample-%s' % (source) - if comp_name not in self._components: - self._components[comp_name] = -1 - else: - self._components[comp_name] = 1 - + comp_name = 'resample-%s-%s' % (source, target_samplerate) feeder = 'input-%s' % (mux['audio']) - self.flow['inputs']['resample-%s-%s' % (source, samplerate)] = { + self.flow['inputs'][comp_name] = { 'type': 'audio-resample', - 'desc': "resample audio from %s to %s Hz" % (source, samplerate), - 'worker': comp_name, + 'desc': "resample audio from %s to %s Hz" % (source, target_samplerate), + 'worker': None, 'feeder': feeder, 'properties': { - 'samplerate': samplerate, + 'samplerate': target_samplerate, }, } @@ -162,113 +151,94 @@ class Planet: if input_resolution == "": raise exception("format definition needs video but no video input given") - resolution = globals['profiles'][profile]['video'] - if input_resolution == resolution: + target_resolution = globals['profiles'][profile]['video'] + if target_resolution == input_resolution: return - if globals['resolutions'][resolution]['rate'] != globals['resolutions'][input_resolution]['rate']: + if globals['resolutions'][target_resolution]['rate'] != globals['resolutions'][input_resolution]['rate']: raise exception("ERROR: video rate conversion is not yet supported!!!") - comp_name = 'resize-%s' % (source) - if comp_name not in self._components: - self._components[comp_name] = -1 - else: - self._components[comp_name] = 1 - + comp_name = 'resize-%s-%s' % (source, target_resolution) feeder = 'input-%s' % (mux['video']) - self.flow['inputs']['resize-%s-%s' % (source, resolution)] = { + self.flow['inputs'][comp_name] = { 'type': 'video-resize', - 'desc': "resize video from %s to %sx%s" % (source, globals['resolutions'][resolution]['width'], - globals['resolutions'][resolution]['height']), - 'worker': comp_name, + 'desc': "resize video from %s to %sx%s" % (source, globals['resolutions'][target_resolution]['width'], + globals['resolutions'][target_resolution]['height']), + 'worker': None, 'feeder': feeder, 'properties': { - 'width': globals['resolutions'][resolution]['width'], - 'height': globals['resolutions'][resolution]['height'], + 'width': globals['resolutions'][target_resolution]['width'], + 'height': globals['resolutions'][target_resolution]['height'], }, } def __generate_audio_encoder(self, mux, format, profile, inputs, globals): encoder = globals['formats'][format]['audio'] bitrate = globals['profiles'][profile]['audio'] + source = mux['audio'].split(':')[0] input_samplerate = inputs[source]['properties']['samplerate'] - samplerate = input_samplerate + target_samplerate = input_samplerate if 'samplerate' in globals['formats'][format]: - samplerate = globals['formats'][format]['samplerate'] + target_samplerate = globals['formats'][format]['samplerate'] feeder = 'input-%s' % (mux['audio']) - if samplerate != input_samplerate: - feeder = 'resample-%s-%s' % (source, samplerate) - - audio_encoder = 'encode-%s-%s-%i-%i' % (source, encoder, bitrate, samplerate) - if audio_encoder in self.flow['encoders_audio']: - return audio_encoder + if target_samplerate != input_samplerate: + feeder = 'resample-%s-%s' % (source, target_samplerate) - comp_name = 'encoder-%s-%s-%s' % (source, encoder, bitrate) - if comp_name not in self._components: - self._components[comp_name] = -1 - else: - self._components[comp_name] = 1 + comp_name = 'encode-%s-%s-%i-%i' % (source, encoder, bitrate, target_samplerate) + if comp_name in self.flow['encoders_audio']: + return comp_name - self.flow['encoders_audio'][audio_encoder] = { + self.flow['encoders_audio'][comp_name] = { 'type': '%s-encode' % encoder, - 'desc': "%s encoder for %i kbit/s @ %i Hz, from %s" % (encoder, bitrate, samplerate, source), - 'worker': comp_name, + 'desc': "%s encoder for %i kbit/s @ %i Hz, from %s" % (encoder, bitrate, target_samplerate, source), + 'worker': None, 'feeder': feeder, 'properties': { 'bitrate': bitrate, }, } - return audio_encoder + return comp_name def __generate_video_encoder(self, mux, format, profile, inputs, globals): encoder = globals['formats'][format]['video'] - resolution = globals['profiles'][profile]['video'] - bitrate = globals['bitrates'][encoder][resolution] + target_resolution = globals['profiles'][profile]['video'] + bitrate = globals['bitrates'][encoder][target_resolution] + source = mux['video'].split(':')[0] input_resolution = inputs[source]['properties']['resolution'] feeder = 'input-%s' % (mux['video']) - if resolution != input_resolution: - feeder = 'resize-%s-%s' % (source, resolution) - - video_encoder = 'encode-%s-%s-%s' % (source, encoder, resolution) - if video_encoder in self.flow['encoders_video']: - return video_encoder + if target_resolution != input_resolution: + feeder = 'resize-%s-%s' % (source, target_resolution) - comp_name = 'encoder-%s-%s-%s' % (source, encoder, resolution) - if comp_name not in self._components: - self._components[comp_name] = -1 - else: - self._components[comp_name] = 1 + comp_name = 'encode-%s-%s-%s' % (source, encoder, target_resolution) + if comp_name in self.flow['encoders_video']: + return comp_name - self.flow['encoders_video'][video_encoder] = { + self.flow['encoders_video'][comp_name] = { 'type': '%s-encode' % encoder, - 'desc': "%s encoder for %sx%s, from %s" % (encoder, globals['resolutions'][resolution]['width'], globals['resolutions'][resolution]['height'], source), - 'worker': comp_name, + 'desc': "%s encoder for %sx%s, from %s" % (encoder, globals['resolutions'][target_resolution]['width'], + globals['resolutions'][target_resolution]['height'], source), + 'worker': None, 'feeder': feeder, 'properties': { 'bitrate': bitrate, }, } - return video_encoder + return comp_name def __generate_muxer(self, mux_name, format, profile, globals, audio_encoder, video_encoder): muxer = globals['formats'][format]['muxer'] - comp_name = 'muxer-%s-%s-%s' % (mux_name, format, profile) - if comp_name not in self._components: - self._components[comp_name] = -1 - else: - self._components[comp_name] = 1 - - self.flow['muxers']['muxer-%s-%s-%s' % (mux_name, format, profile)] = { + comp_name = 'mux-%s-%s-%s' % (mux_name, format, profile) + self.flow['muxers'][comp_name] = { 'type': '%s-mux' % muxer, 'desc': "%s muxer for %s, profile %s" % (format, mux_name, profile), - 'worker': comp_name, + 'worker': None, 'feeder_audio': audio_encoder, 'feeder_video': video_encoder, 'properties': {}, @@ -282,8 +252,8 @@ class Planet: for mux_name, mux in muxes.items(): for format in mux['formats'].keys(): for profile in mux['formats'][format]: - audio_encoder = 'none' - video_encoder = 'none' + audio_encoder = None + video_encoder = None if 'audio' in mux: self.__generate_audio_resampler(mux, format, profile, inputs, globals) audio_encoder = self.__generate_audio_encoder(mux, format, profile, inputs, globals) @@ -332,20 +302,6 @@ if __name__ == '__main__': print("**") __pp.pprint(p.flow) - print("**") - print("****************************************************") - print("** _workers **") - print("**") - __pp.pprint(p._workers) - - print("**") - print("**************************") - print("** _components **") - print("**") - __pp.pprint(p._components) - print("**") - print("****************************************************") - except Exception as e: print("ERROR: while running app: %s" % e) print(traceback.format_exc()) diff --git a/templates/flumotion/default/flv-mux.xml b/templates/flumotion/default/flv-mux.xml index a3706da..be77ddb 100644 --- a/templates/flumotion/default/flv-mux.xml +++ b/templates/flumotion/default/flv-mux.xml @@ -6,7 +6,7 @@ version="{{ globals.version }}"> <eater name="default"> <feed alias="default">{{ component.feeder_audio }}</feed> -%% if component.feeder_video != 'none' +%% if component.feeder_video <feed alias="default-bis">{{ component.feeder_video }}</feed> %% endif </eater> diff --git a/templates/flumotion/default/mkv-mux.xml b/templates/flumotion/default/mkv-mux.xml index 6122327..0be8da0 100644 --- a/templates/flumotion/default/mkv-mux.xml +++ b/templates/flumotion/default/mkv-mux.xml @@ -6,7 +6,7 @@ version="{{ globals.version }}"> <eater name="default"> <feed alias="default">{{ component.feeder_audio }}</feed> -%% if component.feeder_video != 'none' +%% if component.feeder_video <feed alias="default-bis">{{ component.feeder_video }}</feed> %% endif </eater> diff --git a/templates/flumotion/default/mpegts-mux.xml b/templates/flumotion/default/mpegts-mux.xml index 4338fe4..8d8be6a 100644 --- a/templates/flumotion/default/mpegts-mux.xml +++ b/templates/flumotion/default/mpegts-mux.xml @@ -6,7 +6,7 @@ version="{{ globals.version }}"> <eater name="default"> <feed alias="default">{{ component.feeder_audio }}</feed> -%% if component.feeder_video != 'none' +%% if component.feeder_video <feed alias="default-bis">{{ component.feeder_video }}</feed> %% endif </eater> diff --git a/templates/flumotion/default/ogg-mux.xml b/templates/flumotion/default/ogg-mux.xml index 36d7ef5..8827be1 100644 --- a/templates/flumotion/default/ogg-mux.xml +++ b/templates/flumotion/default/ogg-mux.xml @@ -6,7 +6,7 @@ version="{{ globals.version }}"> <eater name="default"> <feed alias="default">{{ component.feeder_audio }}</feed> -%% if component.feeder_video != 'none' +%% if component.feeder_video <feed alias="default-bis">{{ component.feeder_video }}</feed> %% endif </eater> diff --git a/templates/flumotion/default/webm-mux.xml b/templates/flumotion/default/webm-mux.xml index acace74..ac58f13 100644 --- a/templates/flumotion/default/webm-mux.xml +++ b/templates/flumotion/default/webm-mux.xml @@ -6,7 +6,7 @@ version="{{ globals.version }}"> <eater name="default"> <feed alias="default">{{ component.feeder_audio }}</feed> -%% if component.feeder_video != 'none' +%% if component.feeder_video <feed alias="default-bis">{{ component.feeder_video }}</feed> %% endif </eater> |