import socket import time import picamera with picamera.PiCamera() as camera: camera.resolution = (640, 480) camera.framerate = 24 server_socket = socket.socket() server_socket.bind(('0.0.0.0', 8000)) server_socket.listen(0) # Accept a single connection and make a file-like object out of it connection = server_socket.accept().makefile('wb') try: camera.start_recording(connection, format='h264') camera.wait_recording(60) camera.stop_recording() finally: connection.close() server_socket.close()
|Run the Python on Raspberry Pi|
|View on desktop using VLC|
In this scenario, the Pi acts as the server, waiting for a connection from the client. When it accepts a connection, it starts streaming video over it for 60 seconds.
Bo script is needed on the client side - we can simply use VLC with a network URL:
$ vlc tcp/h264://my_pi_address:8000/
There 2~3 seconds delay in my test on Raspberry Pi 2.