forked from peppelinux/debian-python-live555
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
49 lines (37 loc) · 1.29 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
45
46
47
48
import time
import sys
import live555
import threading
# Shows how to use live555 module to pull frames from an RTSP/RTP
# source. Run this (likely first customizing the URL below:
# Example: python3 example.py 10.17.4.118 1 10 out.264
if len(sys.argv) != 5:
print()
print('Usage: python3 example.py cameraIP channel seconds fileOut')
print()
sys.exit(1)
cameraIP = sys.argv[1]
channel = sys.argv[2]
seconds = float(sys.argv[3])
fileOut = sys.argv[4]
# NOTE: the username & password, and the URL path, will vary from one
# camera to another! This URL path works with the Lorex LNB2153:
url = 'rtsp://admin:000000@%s/PSIA/Streaming/channels/%s' % (cameraIP, channel)
fOut = open(fileOut, 'wb')
def oneFrame(codecName, bytes, sec, usec, durUSec):
print('frame for %s: %d bytes' % (codecName, len(bytes)))
fOut.write(b'\0\0\0\1' + bytes)
# Starts pulling frames from the URL, with the provided callback:
useTCP = False
live555.startRTSP(url, oneFrame, useTCP)
# Run Live555's event loop in a background thread:
t = threading.Thread(target=live555.runEventLoop, args=())
t.setDaemon(True)
t.start()
endTime = time.time() + seconds
while time.time() < endTime:
time.sleep(0.1)
# Tell Live555's event loop to stop:
live555.stopEventLoop()
# Wait for the background thread to finish:
t.join()