-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootlab-tx
executable file
·62 lines (47 loc) · 1.94 KB
/
bootlab-tx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
#
# usage: bootlab-tx channel:password
#
import subprocess
import sys, time
# Check args
if len(sys.argv) < 2 or not ':' in sys.argv[1]:
print('usage: bootlab-tx channel:password')
sys.stdout.flush()
exit(1)
channel, password = sys.argv[1].split(':')
# Prepare URL
icecast = 'icecast://source:'+password+'@boot.telemir.fr:8000/'+channel
while True:
# Detect USB audio HW
hw = 'none'
card = subprocess.run('arecord -l | grep USB | awk \'{print $2}\'', shell=True, stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
if card:
hw = card.replace(':', ',')+'0'
# Detect channels
ichan = 2
while True:
test = subprocess.run('arecord -d 1 -f cd -D hw:'+hw+' /zz/foobar.wav -c '+str(ichan), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stderr.decode('utf-8').strip()
if not 'Channels count non available' in test or ichan == 1:
break
ichan -= 1
print('USB soundcard detected with '+str(ichan)+' channels')
sys.stdout.flush()
# Make CMD
command = 'ffmpeg -ac '+str(ichan)+' -f alsa -i hw:'+hw+' -c:a libopus -vbr on -b:a 256k -ac 2 -vn -content_type application/ogg -f ogg '+icecast+' 2>/tmp/bootlab-tx.log'
print('FFMPEG cmd: '+command)
print('FFMPEG log: tail -f /tmp/bootlab-tx.log')
sys.stdout.flush()
try:
ffmpeg = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
ffmpeg.wait()
except:
e = sys.exc_info()[0]
print(e)
sys.stdout.flush()
else:
print('No USB audio detected...')
sys.stdout.flush()
time.sleep(0.5)
subprocess.run('pkill ffmpeg', shell=True, stdout=subprocess.PIPE)
# ffmpeg -ac 2 -f alsa -i hw:1,0 -acodec libopus -ab 256k -ac 2 -content_type application/ogg -f ogg icecast://source:bootlab37*@boot.telemir.fr:8000/bootleg