Skip to content

Instantly share code, notes, and snippets.

@oskar456
Created June 14, 2014 16:25
Show Gist options
  • Save oskar456/50e38fbb29dbd01a7db1 to your computer and use it in GitHub Desktop.
Save oskar456/50e38fbb29dbd01a7db1 to your computer and use it in GitHub Desktop.
MPEG TS to IceCast CGI script
#!/usr/bin/env python
import subprocess
import shlex
import sys
import signal
sys.stdout.write("""Content-Type: audio/mpeg\r
icy-br:192\r
ice-audio-info: ice-samplerate=48000;ice-bitrate=192;ice-channels=2\r
icy-description:CRo 2\r
icy-genre:MooN\r
icy-name:CRo 2 - Praha\r
Cache-Control: no-cache\r
Pragma: no-cache\r
\r\n""")
sys.stdout.flush()
signal.signal(signal.SIGPIPE, signal.SIG_DFL);
nullfile = open("/dev/null", "wb");
wgetcmd = shlex.split("wget -T 5 -t 1 -qO - http://192.168.10.1:8001/cro2")
ts2escmd = shlex.split("ts2es 4369")
lamecmd = shlex.split("lame --mp2input --scale 1.9 --cbr -b 192 --quiet - -")
lameproc = subprocess.Popen(lamecmd, stdin=subprocess.PIPE, stdout=None, stderr=nullfile)
ts2esproc = subprocess.Popen(ts2escmd, stdin=subprocess.PIPE, stdout=lameproc.stdin, stderr=nullfile)
lameproc.stdin.close()
wgetproc = subprocess.Popen(wgetcmd, stdin=None, stdout=ts2esproc.stdin, stderr=nullfile)
ts2esproc.stdin.close()
wgetproc.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment