#!/usr/bin/env python3 # This script eats CRAP and outputs a live GIF-over-HTTP stream. The required bandwidth is about 20kB/s # Copyright (C) 2016 Sebastian Götte # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import io import math import threading import struct import argparse from itertools import chain from contextlib import suppress from PIL import Image, ImageFile from flask import Flask, Response import config import crap frame = None frame_cond = threading.Condition() def framestream(): global frame while True: with frame_cond: frame_cond.wait() img = Image.frombuffer('RGB', (config.display_width, config.display_height), frame, 'raw', 'RGB', 0, 1) yield encode_image(img) def putframe(f): global frame with frame_cond: frame = f frame_cond.notify_all() def file_headers(w, h): yield (b'GIF89a' + struct.pack('