-
Notifications
You must be signed in to change notification settings - Fork 6
/
example.py
executable file
·44 lines (30 loc) · 1.15 KB
/
example.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
#!/usr/bin/env python3
import logging
from multiprocessing import Pool
from control import RTSPClient
from transport import RTPStream
log = logging.getLogger('streamer')
log_format = '[%(asctime)s] [%(name)s] [%(levelname)s] : %(message)s'
logging.basicConfig(level=logging.INFO,format=log_format)
streams = {
'entrance': 'rtsp://username:[email protected]:554/Streaming/Channels/101',
'kitchen': 'rtsp://username:[email protected]:554/Streaming/Channels/101',
'hall': 'rtsp://username:[email protected]:554/Streaming/Channels/102',
'wardrobe': 'rtsp://username:[email protected]:554/Streaming/Channels/102'
}
def save(stream):
name, url = stream[:2]
with RTSPClient(url) as client, RTPStream() as stream:
log.info(f'Connected to <{name}> stream')
client.setup(stream.port)
log.info(f'Sending "PLAY" for <{name}>')
client.play()
log.info(f'Saving chunks for <{name}>')
with open(f'/tmp/{name}','wb') as f:
for chunk in stream.generate():
f.write(chunk)
def main():
pool = Pool(len(streams))
pool.map(save,streams.items())
if __name__ == '__main__':
main()