diff options
-rwxr-xr-x | src/flufigut.py | 93 |
1 files changed, 39 insertions, 54 deletions
diff --git a/src/flufigut.py b/src/flufigut.py index b68c856..5074895 100755 --- a/src/flufigut.py +++ b/src/flufigut.py @@ -122,73 +122,33 @@ class Planet: # # muxes - def __generate_audio_resampler(self, mux, format, profile, inputs, globals): - source = mux['audio'].split(':')[0] - input_samplerate = inputs[source]['properties']['samplerate'] - if 'samplerate' not in globals['formats'][format]: - return None - - target_samplerate = globals['formats'][format]['samplerate'] + def __generate_audio_feeder(self, input, source, input_samplerate, target_samplerate): if target_samplerate == input_samplerate: - return None + return input - feeder = 'input-%s' % (mux['audio']) comp_name = 'resample-%s-%s' % (source, target_samplerate) comp_desc = 'resample audio from % s to % s Hz' % (source, target_samplerate) self.flow['inputs'][comp_name] = { 'type': 'audio-resample', 'desc': comp_desc, 'worker': None, - 'feeder': feeder, + 'feeder': input, 'properties': { 'samplerate': target_samplerate, }, } return comp_name - def __generate_video_resizer(self, mux, format, profile, inputs, globals): - source = mux['video'].split(':')[0] - input_resolution = inputs[source]['properties']['resolution'] - if 'video' not in globals['profiles'][profile]: - return None - - if input_resolution == "": - raise Exception("format definition needs video but no video input given") - - target_resolution = globals['profiles'][profile]['video'] - if target_resolution == input_resolution: - return None - - if globals['resolutions'][target_resolution]['rate'] != globals['resolutions'][input_resolution]['rate']: - raise Exception("ERROR: video rate conversion is not yet supported!!!") - - feeder = 'input-%s' % (mux['video']) - comp_name = 'resize-%s-%s' % (source, target_resolution) - comp_desc = 'resize video from %s to %sx%s' % (source, globals['resolutions'][target_resolution]['width'], - globals['resolutions'][target_resolution]['height']), - self.flow['inputs'][comp_name] = { - 'type': 'video-resize', - 'desc': comp_desc, - 'worker': None, - 'feeder': feeder, - 'properties': { - 'width': globals['resolutions'][target_resolution]['width'], - 'height': globals['resolutions'][target_resolution]['height'], - }, - } - return comp_name - - def __generate_audio_encoder(self, mux, format, profile, inputs, globals, feeder): + def __generate_audio_encoder(self, mux, format, profile, inputs, globals): source = mux['audio'].split(':')[0] encoder = globals['formats'][format]['audio'] bitrate = globals['profiles'][profile]['audio'] - samplerate = inputs[source]['properties']['samplerate'] + input_samplerate = inputs[source]['properties']['samplerate'] + samplerate = input_samplerate if 'samplerate' in globals['formats'][format]: samplerate = globals['formats'][format]['samplerate'] - if not feeder: - feeder = 'input-%s' % (mux['audio']) - + feeder = self.__generate_audio_feeder('input-%s' % (mux['audio']), source, input_samplerate, samplerate) comp_name = 'encode-%s-%s-%i-%i' % (source, encoder, bitrate, samplerate) comp_desc = '%s encoder for %i kbit/s @ %i Hz, from %s' % (encoder, bitrate, samplerate, source), if bitrate == 0: @@ -209,15 +169,42 @@ class Planet: } return comp_name - def __generate_video_encoder(self, mux, format, profile, inputs, globals, feeder): + def __generate_video_feeder(self, input, source, input_resolution, target_resolution, globals): + if globals['resolutions'][target_resolution]['rate'] != globals['resolutions'][input_resolution]['rate']: + raise Exception("ERROR: video rate conversion is not supported!!!") + + if target_resolution == input_resolution: + return input + + comp_name = 'resize-%s-%s' % (source, target_resolution) + comp_desc = 'resize video from %s to %sx%s' % (source, globals['resolutions'][target_resolution]['width'], + globals['resolutions'][target_resolution]['height']), + self.flow['inputs'][comp_name] = { + 'type': 'video-resize', + 'desc': comp_desc, + 'worker': None, + 'feeder': input, + 'properties': { + 'width': globals['resolutions'][target_resolution]['width'], + 'height': globals['resolutions'][target_resolution]['height'], + }, + } + return comp_name + + def __generate_video_encoder(self, mux, format, profile, inputs, globals): + if 'video' not in globals['profiles'][profile]: + return None + source = mux['video'].split(':')[0] encoder = globals['formats'][format]['video'] + input_resolution = inputs[source]['properties']['resolution'] resolution = globals['profiles'][profile]['video'] bitrate = globals['bitrates'][encoder][resolution] - if not feeder: - feeder = 'input-%s' % (mux['video']) + if input_resolution == "": + raise Exception("format definition needs video but no video input given") + feeder = self.__generate_video_feeder('input-%s' % (mux['video']), source, input_resolution, resolution, globals) comp_name = 'encode-%s-%s-%s' % (source, encoder, resolution) comp_desc = '%s encoder for %sx%s, from %s' % (encoder, globals['resolutions'][resolution]['width'], globals['resolutions'][resolution]['height'], source), @@ -261,11 +248,9 @@ class Planet: audio_encoder = None video_encoder = None if 'audio' in mux: - resampler = self.__generate_audio_resampler(mux, format, profile, inputs, globals) - audio_encoder = self.__generate_audio_encoder(mux, format, profile, inputs, globals, resampler) + audio_encoder = self.__generate_audio_encoder(mux, format, profile, inputs, globals) if 'video' in mux: - resizer = self.__generate_video_resizer(mux, format, profile, inputs, globals) - video_encoder = self.__generate_video_encoder(mux, format, profile, inputs, globals, resizer) + video_encoder = self.__generate_video_encoder(mux, format, profile, inputs, globals) self.__generate_muxer(mux_name, format, profile, globals, audio_encoder, video_encoder) |