summaryrefslogtreecommitdiff
path: root/examples/mjpeg_stream.py
blob: 6b8f9d6b33677e574bdc4dcc287bc9ff0d8f9cbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
import subprocess


def application(env, start_response):

    boundary = 'uwsgi_mjpeg_frame'

    start_response('200 Ok', [
        ('Cache-Control', 'no-cache'),
        ('Cache-Control', 'private'),
        ('Pragma', 'no-cache'),
        ('Content-Type', 'multipart/x-mixed-replace; boundary=' + boundary),
    ])

    yield "--%s\r\n" % boundary

    while 1:
        yield "Content-Type: image/jpeg\r\n\r\n"
        print subprocess.call('screencapture -t jpg -m -T 1 screenshot.jpg', shell=True)
        f = open('screenshot.jpg')
        yield env['wsgi.file_wrapper'](f)
        yield "\r\n--%s\r\n" % boundary
        # subprocess.call('./isightcapture -w 640 -h 480 screenshot.jpg', shell=True)