Want to watch a flash live stream but your browser is not able to play the stream smoothly ? Or maybe you simply hate flash movies… Here is the solution ! Catch the stream and pipe it to mplayer. Here is small python script to set the required iptables and start mplayer afterwards.
Usage: Start the script; then open / reload the website that includes the flash player in your browser.
#!/usr/bin/python3
import time
import subprocess
###############
retries = 3
sleep = 3
###############
iptAdd = "sudo iptables -t nat -A OUTPUT -p tcp --dport 1935 -j REDIRECT"
iptDel = "sudo iptables -t nat -D OUTPUT -p tcp --dport 1935 -j REDIRECT"
iptc = subprocess.Popen(iptAdd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
iptc.wait()
_, stderr = iptc.communicate()
if not len(stderr) == 0:
print(stderr)
exit(0)
try:
rtmpsrv = subprocess.Popen("rtmpsrv", stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0)
while True:
line = rtmpsrv.stderr.readline()
if line.find(b"Closing connection") >= 0:
rtmpsrv.kill()
break
time.sleep(0.5)
stdout, _ = rtmpsrv.communicate()
rtmpdump = b"".join(stdout.split(b"\n"))
except:
rtmpdump = None
iptc = subprocess.Popen(iptDel, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
iptc.wait()
_, stderr = iptc.communicate()
if not len(stderr) == 0:
print("Could not detect stream.")
print(stderr)
exit(0)
if not rtmpdump is None:
rtmpdump = rtmpdump.decode("ASCII")
print("Found rtmpdump command: '%s'\n" % rtmpdump)
mp = "%s | mplayer -" % rtmpdump[:rtmpdump.find(" -o \"")]
print("Executing: '%s'\n" % mp)
retry = 0
while True:
mplayer = subprocess.Popen(mp, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
mplayer.wait()
_, stderr = mplayer.communicate()
if stderr.find(b"ERROR") >= 0:
print("Error :(")
if retry < retries:
time.sleep(sleep)
retry += 1
print("Retry (%d)" % retry)
else:
print("Giving up")
break
else:
break
streaMplayer - play flash streams with mplayer,
0 Comments.