简体   繁体   English

通过TCP查看h264流

[英]Viewing h264 stream over TCP

I have a small wifi based FPV camera for a drone. 我有一个基于wifi的小型FPV无人机摄像头。 I've managed to get it to the point where I can download and save an h264 file using python. 我已经设法使其可以使用python下载和保存h264文件。

TCP_IP = '193.168.0.1'
TCP_PORT = 6200
BUFFER_SIZE = 2056

f = open('stream.h264', 'wb')
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((TCP_IP,TCP_PORT))
while True:
    data = sock.recv(BUFFER_SIZE)
    f.write(data)
    print("Writing")
sock.close()
f.close()

What I've been trying to do for a while now is play the stream. 我已经尝试了一段时间了,是在播放视频。 I've found the stream, I can download it and save it, but now I want to open it live. 我找到了流,可以下载并保存它,但是现在我想实时打开它。 I've tried using VLC's 'open network stream' with a variety of options, but none of them seemed to work. 我曾尝试将VLC的“开放网络流”与多种选项结合使用,但它们似乎都不起作用。

I successfully output to mplayer using 我成功使用输出到mplayer

data = sock.recv(BUFFER_SIZE) sys.stdout.buffer.write(data)

and then having mplayer pipe the input 然后让mplayer管道输入

python cam.py - | mplayer -fps 20 -nosound -vc ffh264 -noidx -mc 0 -

It is a simple way, yes: send H.264 NALU stream (you put 0,0,0,1 prefix before each nal unit and it is ok). 这是一个简单的方法,可以:发送H.264 NALU流(在每个nal单元之前放置0,0,0,1前缀,可以)。

If you want something more cool, then you can add packing to RTP and send it via multicast. 如果您想要更酷的东西,则可以将打包添加到RTP并通过多播发送。 It will be rather simple to code and easy to read. 这将是相当简单的编码和易于阅读。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM