-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstream.py
executable file
·50 lines (37 loc) · 1.22 KB
/
stream.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import subprocess as sp
import threading
import time
import os
import signal
class ffmpegStreamThread(threading.Thread):
def __init__(self, ip, clientID):
#ip = '192.168.1.77'
#clientID = 'picam2'
self.stdout = None
self.stderr = None
self.ip = ip
self.clientID = clientID
threading.Thread.__init__(self)
self.event = threading.Event()
def stopped(self):
return self.event.isSet()
def stop(self):
self.event.set()
def run(self):
self.startProcess(self.ip, self.clientID)
def startProcess(self, ip, clientID):
FFMPEG_BIN = 'ffmpeg'
command = [
FFMPEG_BIN,
'-i', 'tcp://127.0.0.1:8181?listen',
'-c:v', 'copy',
'-c:a', 'aac',
'-ar', '44100',
'-ab', '40000',
'-timeout', '3',
'-f', 'flv rtmp://'+ip+'/live/'+clientID
]
self.pro = sp.Popen(command, stdout=sp.PIPE, bufsize = 10**8)
self.stdout, self.stderr = p.communicate()
def stopProcess(self):
os.killpg(os.getpgid(self.pro.pid),signal.SIGTERM)