简体   繁体   中英

Video stream over UDP

I'm currently trying to stream video over UDP from an RPi (running Raspbian) to my MBP Retina (Yosemite).

I have a working script to stream over TCP, but I understand that UDP is the better option for video streaming, however I'm not really sure how to do it. Here is what I have so far:

import socket, picamera, time

UDPsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
file = UDPsock.makefile('wb')

class videostream():
    def __init__(self):
        print "Camera Class Initialised"
    def stream(self):
        with picamera.PiCamera() as camera:
            camera.resolution = (640, 480)
            camera.start_preview()
            time.sleep(2)
            camera.start_recording(file, format='h264')
            camera.wait_recording(60)
            camera.stop_recording()

camera = videostream()
stream = camera.stream()
address = ("10.0.1.29", 8000)
UDPsock.sendto(stream, address)

It gives me this error: socket.error: [Errno 89] Destination address required on the line: camera.stop_recording() .

I'm fairly new to networking within Python so forgive any stupid mistakes.

I can't immediately tell you the fix, but I can spot a whole bunch of errors:

  • assigning to the variable "file". ("file" is a Python keyword; BAD MOVE)
  • it looks to me like camera.stream() return nothing... therefore "stream" will be "None"
  • I don't think sendto() accepts a file object; I've only ever seen it used with strings, and I think the docs support this.

Good luck!

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