From 374c262caa9198fc26923b6c7488704531c3ea1a Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 1 Oct 2012 01:22:33 +0200 Subject: generate encoder and muxer automatically --- src/flufigut.py | 162 ++++++++++++++++++++++--------------------- src/test.json | 2 +- templates/example/planet.xml | 7 +- 3 files changed, 89 insertions(+), 82 deletions(-) diff --git a/src/flufigut.py b/src/flufigut.py index 83ab005..a47e544 100755 --- a/src/flufigut.py +++ b/src/flufigut.py @@ -54,16 +54,20 @@ cf.close(); atmosphere = {} flow = {} machines = {} +globals = config['globals'] +input = config['input'] +transcode = config['transcode'] +stream = config['stream'] ### generate porter for all streamer/machines ################### # idx = 0 -for streamer in config['streamer']: +for streamer in stream: worker = 'streamer%i'%(idx) port = streamer['config']['port'] found = False - for machine in config['globals']['machines'].keys(): - if worker in config['globals']['machines'][machine]: + for machine in globals['machines'].keys(): + if worker in globals['machines'][machine]: if machine in machines: if 'porter' in machines[machine]: if port in machines[machine]['porter']: @@ -101,28 +105,28 @@ for streamer in config['streamer']: flow['input'] = {} flow['input']['raw-input'] = { - 'type': config['input']['source'], - 'desc': "capture raw AV from %s" % config['input']['source'], + 'type': input['source'], + 'desc': "capture raw AV from %s" % input['source'], 'worker': 'input', 'properties': {}, } -for property in config['input'].keys(): +for property in input.keys(): if property == 'samplerate': - flow['input']['raw-input']['properties'][property] = config['input']['samplerate'] + flow['input']['raw-input']['properties'][property] = input['samplerate'] elif property == 'resolution': - flow['input']['raw-input']['properties']['width'] = config['globals']['resolutions'][config['input'][property]]['width'] - flow['input']['raw-input']['properties']['height'] = config['globals']['resolutions'][config['input'][property]]['height'] - flow['input']['raw-input']['properties']['framerate'] = config['globals']['resolutions'][config['input'][property]]['rate'] + flow['input']['raw-input']['properties']['width'] = globals['resolutions'][input[property]]['width'] + flow['input']['raw-input']['properties']['height'] = globals['resolutions'][input[property]]['height'] + flow['input']['raw-input']['properties']['framerate'] = globals['resolutions'][input[property]]['rate'] elif property != 'source': - flow['input']['raw-input']['properties'][property] = config['input'][property] + flow['input']['raw-input']['properties'][property] = input[property] resolutions = [ ] -for format in config['transcode'].keys(): - for profile in config['transcode'][format]: - resolution = config['globals']['profiles'][profile]['video'] +for format in transcode.keys(): + for profile in transcode[format]: + resolution = globals['profiles'][profile]['video'] if resolution not in resolutions: - if config['input']['resolution'] != resolution: - if config['globals']['resolutions'][resolution]['rate'] != config['globals']['resolutions'][config['input']['resolution']]['rate']: + if input['resolution'] != resolution: + if globals['resolutions'][resolution]['rate'] != globals['resolutions'][input['resolution']]['rate']: print "video rate conversion is not yet supported!!!" sys.exit(-1) resolutions.append(resolution) @@ -130,22 +134,22 @@ for format in config['transcode'].keys(): for resolution in resolutions: flow['input']['resize-%s' % resolution] = { 'type': 'video-resize', - 'desc': "resize video to %sx%s" % (config['globals']['resolutions'][resolution]['width'], config['globals']['resolutions'][resolution]['height']), + 'desc': "resize video to %sx%s" % (globals['resolutions'][resolution]['width'], globals['resolutions'][resolution]['height']), 'worker': 'input', 'feeder': 'raw-input:video', 'properties': { - 'width': config['globals']['resolutions'][resolution]['width'], - 'height': config['globals']['resolutions'][resolution]['height'], + 'width': globals['resolutions'][resolution]['width'], + 'height': globals['resolutions'][resolution]['height'], }, } samplerates = [ ] -for format in config['globals']['formats'].keys(): - if 'samplerate' in config['globals']['formats'][format]: - samplerate = config['globals']['formats'][format]['samplerate'] +for format in globals['formats'].keys(): + if 'samplerate' in globals['formats'][format]: + samplerate = globals['formats'][format]['samplerate'] if samplerate not in samplerates: - if config['input']['samplerate'] != samplerate: + if input['samplerate'] != samplerate: samplerates.append(samplerate) for samplerate in samplerates: @@ -160,65 +164,63 @@ for samplerate in samplerates: } ### generate encoder and muxer components ####################### -flow['encoder'] = {} +flow['encoder_video'] = {} +flow['encoder_audio'] = {} flow['muxer'] = {} -# for encoder in config['encoder']['video'].keys(): -# for resolution in config['encoder']['video'][encoder].keys(): -# if resolution == config['input']['resolution']: -# feeder = 'raw-input:video' -# else: -# feeder = 'resize-%s' % resolution - -# flow['encoder']['encode-%s-%s' % (encoder, resolution)] = { -# 'type': '%s-encode' % encoder, -# 'desc': "%s encoder for %sx%s" % (encoder, config['globals']['resolutions'][resolution]['width'], config['globals']['resolutions'][resolution]['height']), -# 'worker': 'encoder-%s' % encoder, -# 'feeder': feeder, -# 'properties': { -# 'bitrate': config['encoder']['video'][encoder][resolution], -# }, -# } - -# for encoder in config['encoder']['audio'].keys(): -# for audiorate in config['encoder']['audio'][encoder]: -# if config['globals']['audiorates'][audiorate]['samplerate'] == config['input']['samplerate']: -# feeder = 'raw-input:audio' -# else: -# feeder = 'resample-%s' % config['globals']['audiorates'][audiorate]['samplerate'] - -# flow['encoder']['encode-%s-%s' % (encoder, audiorate)] = { -# 'type': '%s-encode' % encoder, -# 'desc': "%s encoder for %i kbit/s @ %i Hz" % (encoder, config['globals']['audiorates'][audiorate]['bitrate'], config['globals']['audiorates'][audiorate]['samplerate']), -# 'worker': 'encoder-%s' % encoder, -# 'feeder': feeder, -# 'properties': { -# 'bitrate': config['globals']['audiorates'][audiorate]['bitrate'], -# }, -# } - -# for format in config['muxer'].keys(): -# muxer = config['globals']['formats'][format]['muxer'] - -# for profile in config['muxer'][format]: -# resolution = config['globals']['profiles'][profile]['video'] -# arate = config['globals']['profiles'][profile]['audio'] - -# feeder_audio = 'encoder-%s-%s' % (config['globals']['formats'][format]['audio'], arate) -# if 'video' in config['globals']['formats'][format]: -# feeder_video = 'encoder-%s-%s' % (config['globals']['formats'][format]['video'], resolution) -# else: -# feeder_video = 'none' - -# flow['muxer']['muxer-%s-%s' % (muxer, profile)] = { -# 'type': '%s-mux' % muxer, -# 'desc': "%s muxer profile %s" % (format, profile), -# 'worker': 'muxer-%s' % muxer, -# 'feeder_audio': feeder_audio, -# 'feeder_video': feeder_video, -# 'properties': {}, -# } +for format in transcode.keys(): + for profile in transcode[format]: + video_encoder = 'none' + if 'video' in globals['formats'][format]: + encoder = globals['formats'][format]['video'] + resolution = globals['profiles'][profile]['video'] + bitrate = globals['bitrates'][encoder][resolution] + if resolution == input['resolution']: + feeder = 'raw-input:video' + else: + feeder = 'resize-%s' % resolution + video_encoder = 'encode-%s-%s' % (encoder, resolution) + flow['encoder_video'][video_encoder] = { + 'type': '%s-encode' % encoder, + 'desc': "%s encoder for %sx%s" % (encoder, globals['resolutions'][resolution]['width'], globals['resolutions'][resolution]['height']), + 'worker': 'encoder-%s' % encoder, + 'feeder': feeder, + 'properties': { + 'bitrate': bitrate, + }, + } + + audio_encoder = 'none' + if 'audio' in globals['formats'][format]: + encoder = globals['formats'][format]['audio'] + bitrate = globals['profiles'][profile]['audio'] + if 'samplerate' in globals['formats'][format]: + samplerate = globals['formats'][format]['samplerate'] + feeder = 'resample-%s' % samplerate + else: + samplerate = input['samplerate'] + feeder = 'raw-input:audio' + audio_encoder = 'encode-%s-%i-%i' % (encoder, bitrate, samplerate) + flow['encoder_audio'][audio_encoder] = { + 'type': '%s-encode' % encoder, + 'desc': "%s encoder for %i kbit/s @ %i Hz" % (encoder, bitrate, samplerate), + 'worker': 'encoder-%s' % encoder, + 'feeder': feeder, + 'properties': { + 'bitrate': bitrate, + }, + } + muxer = globals['formats'][format]['muxer'] + flow['muxer']['muxer-%s-%s' % (muxer, profile)] = { + 'type': '%s-mux' % muxer, + 'desc': "%s muxer profile %s" % (format, profile), + 'worker': 'muxer-%s' % muxer, + 'feeder_audio': audio_encoder, + 'feeder_video': video_encoder, + 'properties': {}, + } + ### generate streamer components ################################ flow['streamer'] = {} @@ -229,7 +231,7 @@ flow['streamer'] = {} # env = Environment(loader=FileSystemLoader('../templates/%s/' % (sys.argv[1])), line_statement_prefix = '%%') template = env.get_template('planet.xml') -planet = template.render(globals=config['globals'], atmosphere=atmosphere, flow=flow) +planet = template.render(globals=globals, atmosphere=atmosphere, flow=flow) sys.stdout.write(planet.encode("utf8")) diff --git a/src/test.json b/src/test.json index f4aad1c..0a2c7c9 100644 --- a/src/test.json +++ b/src/test.json @@ -43,7 +43,7 @@ "webm": [ "high", "medium", "low" ], "ogg-audio": [ "high" ] }, - "streamer": [ + "stream": [ { "flash": [ "high", "medium", "low" ], "webm": [ "high", "medium", "low" ], "ogg-audio": [ "high" ], "config": { "port": 8000, "max-con": 5 } }, diff --git a/templates/example/planet.xml b/templates/example/planet.xml index 0d5e8fc..547531c 100644 --- a/templates/example/planet.xml +++ b/templates/example/planet.xml @@ -16,7 +16,12 @@ {% endfor %} -{% for name, component in flow['encoder'].items() %} + +{% for name, component in flow['encoder_video'].items() %} +{% include '%s.xml' % component.type %} +{% endfor %} + +{% for name, component in flow['encoder_audio'].items() %} {% include '%s.xml' % component.type %} {% endfor %} -- cgit v1.2.3