Skip to content

Instantly share code, notes, and snippets.

@spikedrba
Created April 8, 2015 00:36
Show Gist options
  • Save spikedrba/38a90e76cfce43c5e358 to your computer and use it in GitHub Desktop.
Save spikedrba/38a90e76cfce43c5e358 to your computer and use it in GitHub Desktop.
picamera mjpeg streaming test
#!/usr/bin/env python
import picamera
import socket
with picamera.PiCamera() as camera:
camera.resolution = (1296, 730)
camera.vflip = True
camera.start_preview()
print "creating the socket..."
server_socket = socket.socket()
server_socket.bind(('0.0.0.0', 8001))
server_socket.listen(5)
connection = server_socket.accept()[0].makefile('wb')
print "connection ready!"
try:
print "start recording"
camera.start_recording(connection, format='mjpeg')
camera.wait_recording(60)
camera.stop_recording()
print "stop recording"
finally:
connection.close()
server_socket.close()
camera.stop_preview()
and the html page:
<html>
<head>
<style type="text/css">
#ui-content-stream {
background:url('http://192.168.0.37:8001') no-repeat;
background-size: auto 100% !important;
background-position: center;
}
</style>
<body>
<div id="ui-content-stream">
</div>
</body>
<html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment