简体   繁体   中英

Viewing h264 stream over TCP

I have a small wifi based FPV camera for a drone. I've managed to get it to the point where I can download and save an h264 file using python.

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.

I successfully output to mplayer using

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

and then having mplayer pipe the input

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).

If you want something more cool, then you can add packing to RTP and send it via multicast. It will be rather simple to code and easy to read.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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