-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlivestream_server.py
31 lines (29 loc) · 1.04 KB
/
livestream_server.py
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
import socket
import subprocess
# Start a socket listening for connections on 0.0.0.0:8000 (0.0.0.0 means
# all interfaces)
server_socket = socket.socket()
server_socket.bind(('0.0.0.0', 8000))
server_socket.listen(0)
# Accept a single connection and make a file-like object out of it
connection = server_socket.accept()[0].makefile('rb')
try:
# Run a viewer with an appropriate command line. Uncomment the mplayer
# version if you would prefer to use mplayer instead of VLC
#cmdline = ['vlc', '--demux', 'h264', '-']
cmdline = ['mplayer', '-fps', '31', '-cache', '1024', '-']
print "setup cmdline"
player = subprocess.Popen(cmdline, stdin=subprocess.PIPE)
print "ran subprocess"
while True:
print "reading data"
# Repeatedly read 1k of data from the connection and write it to
# the media player's stdin
data = connection.read(1024)
if not data:
break
player.stdin.write(data)
finally:
connection.close()
server_socket.close()
player.terminate()