简体   繁体   English

UDP上的视频流

[英]Video stream over UDP

I'm currently trying to stream video over UDP from an RPi (running Raspbian) to my MBP Retina (Yosemite). 我目前正在尝试通过UDP将视频从RPi(运行Raspbian)传输到我的MBP Retina(优胜美地)。

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. 我有一个工作脚本可以通过TCP进行流传输,但是我知道UDP是视频流传输的更好选择,但是我不确定如何做到这一点。 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() . 它给了我这个错误: socket.error: [Errno 89] Destination address required行上socket.error: [Errno 89] Destination address requiredcamera.stop_recording()

I'm fairly new to networking within Python so forgive any stupid mistakes. 我对使用Python联网很陌生,因此请原谅任何愚蠢的错误。

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) (“文件”是Python关键字; BAD MOVE)
  • it looks to me like camera.stream() return nothing... therefore "stream" will be "None" 在我看来,就像camera.stream()什么也不返回...因此,“ stream”将为“ None”
  • I don't think sendto() accepts a file object; 我不认为sendto()接受文件对象; I've only ever seen it used with strings, and I think the docs support this. 我只见过它与字符串一起使用,我认为文档支持此功能。

Good luck! 祝好运!

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

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