我正在尝试使用Python从IP摄像机传输RTP数据包。
我可以使用RTSP协议发送描述、设置和播放命令,但是,我无法使用RTP开始流式传输实际的视频流。
代码如下:
import socket
def printrec(recst):
recs=recst.split('\r\n')
for rec in recs:
print rec
dest="DESCRIBE rtsp://admin:12345@192.168.1.74 RTSP/1.0\r\nCSeq: 2\r\nUser-Agent: python\r\nAccept: application/sdp\r\n\r\n"
setu="SETUP rtsp://admin:12345@192.168.1.74/trackID=1 RTSP/1.0\r\nCSeq: 3\r\nUser-Agent: python\r\nTransport: RTP/AVP;unicast;client_port=60784-60785\r\n\r\n"
play="PLAY rtsp://admin:12345@192.168.1.74/ RTSP/1.0\r\nCSeq: 5\r\nUser-Agent: python\r\nSession: SESID\r\nRange: npt=0.000-\r\n\r\n"
# .. here SESID will be substituted with the session id that SETUP returns us ..
ip="192.168.1.74"
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip,554))
s.send(dest)
recst=s.recv(4096)
printrec(recst)
# etc. then the same for the strins "setu" and "play"
....
安装程序答复我:
RTSP/1.0 200 OK
CSeq: 3
Session: 1117448817;timeout=60
Transport: RTP/AVP;unicast;client_port=60784-60785;server_port=8214-8215;ssrc=40d35c30;mode="play"
Date: Mon, Jan 19 2015 11:10:08 GMT
所以我们有客户机端口60784和60785以及服务器端口8214和8215。
接下来,play回复我:
RTSP/1.0 200 OK
CSeq: 5
Session: 1117448817
RTP-Info: url=rtsp://admin:12345@192.168.1.74/trackID=1;seq=3539; rtptime=16026930
Date: Mon, Jan 19 2015 11:10:08 GMT
接下来,我该怎么做才能开始接收RTP包? 打开一个UDP套接字,如下所示?
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.bind((ip, serverport))
sock.recv(4096)
但我什么也得不到。。(停了下来)
对不起,我对插座的了解太差了。。!
所以
经过大量的google和wireshark分析,我找到了正确的解决方案。
我将在这里发布最终的演示代码。。我想这对社区是有用的。
如果你想用python读取ip cams并将H264流转储到一个可食文件中,这就是你要寻找的东西。
享受吧!
这就是我现在使用的:
更多信息请参见https://elsampsa.github.io/valkka-examples/
相关问题 更多 >
编程相关推荐