I want to stream the live video feed captured from a camera attached to my Raspberry Pi Zero to some browser with as low latency as possible (<1s). My end goal is attaching the Pi Zero & Camera to a drone and streaming the video via LTE.
However, I'm kind of lost in the jungle of different solutions that exist here (MJPEG, RTMP, RTSP, WebRTC).
So far, I tried a simple mjpeg streamer following this guide :
import cv2
import pyshine as ps # pip3 install pyshine==0.0.9
HTML="""
<html>
<head>
<title>PyShine Live Streaming</title>
</head>
<body>
<center><h1> PyShine Live Streaming using OpenCV </h1></center>
<center><img src="stream.mjpg" width='320' height='240' autoplay playsinline></center>
</body>
</html>
"""
def main():
StreamProps = ps.StreamProps
StreamProps.set_Page(StreamProps,HTML)
address = ('127.0.0.1',9000) # Enter your IP address
try:
StreamProps.set_Mode(StreamProps,'cv2')
capture = cv2.VideoCapture(0)
if capture.isOpened():
capture.set(cv2.CAP_PROP_BUFFERSIZE,2)
capture.set(cv2.CAP_PROP_FRAME_WIDTH,240)
capture.set(cv2.CAP_PROP_FRAME_HEIGHT,320)
capture.set(cv2.CAP_PROP_FPS,8)
StreamProps.set_Capture(StreamProps,capture)
StreamProps.set_Quality(StreamProps,40)
server = ps.Streamer(address,StreamProps)
print('Server started at','http://'+address[0]+':'+str(address[1]))
server.serve_forever()
except KeyboardInterrupt:
capture.release()
server.socket.close()
if __name__=='__main__':
main()
While the latency of this simple solution is sufficiently low, it's nowhere near robust enough for my use case. Whenever the connection is interrupted, the stream stops until the browser is refreshed. With slow internet, the stream tends to have a large delay (15s or more) after a while.
What kind of solution should I use for my use case?
Thanks for your help!