-1

I am trying to stream images from a Camera on my Raspberry Pi via UDP. I'm receiving / displaying them on an Android device.

According to my calculations, my application sends at a maximum rate of 10fps, but I need 25 fps.

Does anyone know how to speed my solution up, or have a better solution?

My code is as follows

sock=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.connect((UDP_IP, UDP_PORT))
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 30
rawCapture = PiRGBArray(camera, size=(640, 480))
time.sleep(0.1)

for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
    image = frame.array
    img = Image.fromarray(image,'RGB')
    output = StringIO.StringIO()
    img.save(output, format='JPEG')
    contents = output.getvalue()
    output.close()

    sock.send(contents)
    key = cv2.waitKey(1) & 0xFF
    rawCapture.truncate(0)
sock.close
J Richard Snape
  • 20,116
  • 5
  • 51
  • 79
  • Please leave out begging and thanks from your posts (re-read the help->tour: no chit-chat). Your question ("Knows no better solution?") is unclear, you might want to rewrite that. – Anthon May 11 '15 at 03:34
  • Hi, your question came to me in the "Help and Improvement" review queue. In particular I've: a) moved the android tagas this seems to be Python code to run on a R-Pi. I had to guess you're viewing the stream on an Android device - please edit again if not the case. b) edited the English a little - no problem if it's not your first language (lots of people same on here) but try to get the question precise. c) removed extra `'` in the code - probably typo was messing up code auto-colour. Good luck – J Richard Snape May 13 '15 at 09:42

1 Answers1

0

No need to reinvent the wheel here. Are you trying to make an IP camera? Implement ONVIF streaming. See "5.1.4 JPEG over RTP" for JPEG over UDP format

msh
  • 2,700
  • 1
  • 17
  • 23