From f06786518f40ec6d5013a3035c9d4101a22bfa10 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Wed, 14 Sep 2016 08:43:15 +0200 Subject: record-all-audio-streams example: pep8ify * Indent by 4 spaces * Remove semicolons * Use format() over percent formating --- example-scripts/ffmpeg/record-all-audio-streams.py | 47 +++++++++++----------- 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'example-scripts/ffmpeg/record-all-audio-streams.py') diff --git a/example-scripts/ffmpeg/record-all-audio-streams.py b/example-scripts/ffmpeg/record-all-audio-streams.py index f5bff8f..29cfd6b 100755 --- a/example-scripts/ffmpeg/record-all-audio-streams.py +++ b/example-scripts/ffmpeg/record-all-audio-streams.py @@ -14,29 +14,28 @@ host = 'localhost' port = 9999 log.info('Connecting to %s:%u', host, port) -conn = socket.create_connection( (host, port) ) +conn = socket.create_connection((host, port)) fd = conn.makefile('rw') log.info('Fetching Config from Server') -fd.write("get_config\n"); +fd.write("get_config\n") fd.flush() for line in fd: - if line.startswith('server_config'): - words = line.split(' ') - args = words[1:] - server_config_json = " ".join(args) - log.info('Received Config from Server') - break + if line.startswith('server_config'): + [cmd, arg] = line.split(' ', 1) + server_config_json = arg + log.info('Received Config from Server') + break log.info('Parsing Server-Config') server_config = json.loads(server_config_json) + def getlist(self, section, option): - return [x.strip() for x in self.get(section, option).split(',')] + return [x.strip() for x in self.get(section, option).split(',')] SafeConfigParser.getlist = getlist - config = SafeConfigParser() config.read_dict(server_config) @@ -45,26 +44,26 @@ sources = config.getlist('mix', 'sources') inputs = [] maps = [] for idx, source in enumerate(sources): - inputs.append('-i tcp://localhost:%u' % (13000+idx)) - maps.append('-map %u:a -metadata:s:a:%u language=und' % (idx, idx)) + inputs.append('-i tcp://localhost:{:d}'.format(13000 + idx)) + maps.append('-map {0:d}:a -metadata:s:a:{0:d} language=und'.format(idx)) try: - output = sys.argv[1] + output = sys.argv[1] except: - output = 'output.ts' + output = 'output.ts' cmd = """ ffmpeg \ - -hide_banner - -y -nostdin - %s - -ac 2 -channel_layout stereo - %s - -c:a mp2 -b:a 192k -ac:a 2 -ar:a 48000 - -flags +global_header -flags +ilme+ildct - -f mpegts - %s -""" % (' '.join(inputs), ' '.join(maps), output) + -hide_banner + -y -nostdin + {} + -ac 2 -channel_layout stereo + {} + -c:a mp2 -b:a 192k -ac:a 2 -ar:a 48000 + -flags +global_header -flags +ilme+ildct + -f mpegts + {} +""".format(' '.join(inputs), ' '.join(maps), output) log.info('running command:\n%s', cmd) args = shlex.split(cmd) p = subprocess.run(args) -- cgit v1.2.3