diff options
author | MaZderMind <git@mazdermind.de> | 2016-08-27 18:45:09 +0200 |
---|---|---|
committer | MaZderMind <git@mazdermind.de> | 2016-08-27 18:45:09 +0200 |
commit | f52ea2bc14180d261af0edf5728861bb7a0869c8 (patch) | |
tree | fd02d357128e9784fa898ac66a8275663e025ec8 /example-scripts/ffmpeg | |
parent | 9564e26f334fbec69722d66c4163b5a6c7b0ea0f (diff) |
adds example script for recording all audio-tracks, fixes #64
Diffstat (limited to 'example-scripts/ffmpeg')
-rwxr-xr-x | example-scripts/ffmpeg/record-all-audio-streams.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/example-scripts/ffmpeg/record-all-audio-streams.py b/example-scripts/ffmpeg/record-all-audio-streams.py new file mode 100755 index 0000000..f5bff8f --- /dev/null +++ b/example-scripts/ffmpeg/record-all-audio-streams.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +import socket +import sys +import json +import shlex +import subprocess +import logging +from configparser import SafeConfigParser + +logging.basicConfig(level=logging.DEBUG) +log = logging.getLogger('record-all-audio-streams') + +host = 'localhost' +port = 9999 + +log.info('Connecting to %s:%u', host, port) +conn = socket.create_connection( (host, port) ) +fd = conn.makefile('rw') + +log.info('Fetching Config from Server') +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 + +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(',')] + +SafeConfigParser.getlist = getlist + + +config = SafeConfigParser() +config.read_dict(server_config) + +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)) + +try: + output = sys.argv[1] +except: + 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) +log.info('running command:\n%s', cmd) +args = shlex.split(cmd) +p = subprocess.run(args) +sys.exit(p.returncode) |