-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathpi_video_client.py
More file actions
28 lines (25 loc) · 766 Bytes
/
pi_video_client.py
File metadata and controls
28 lines (25 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import io
import socket
import struct
import time
import picamera
import sys
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((sys.argv[1], int(sys.argv[2])))
connection = client_socket.makefile('wb')
try:
with picamera.PiCamera() as camera:
camera.resolution = (640, 480)
print("starting Camera...........")
time.sleep(2)
stream = io.BytesIO()
for foo in camera.capture_continuous(stream, 'jpeg'):
connection.write(struct.pack('<L', stream.tell()))
connection.flush()
stream.seek(0)
connection.write(stream.read())
stream.seek(0)
stream.truncate()
finally:
connection.close()
client_socket.close()