From 34f2064f05367a1e233dc6a644c03dd46b0bfd1f Mon Sep 17 00:00:00 2001 From: jaseg Date: Sat, 2 Jan 2016 16:43:20 +0100 Subject: Host: Add GIF streaming tool --- host/gifstream.py | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ host/viewer.py | 6 --- 2 files changed, 111 insertions(+), 6 deletions(-) create mode 100755 host/gifstream.py diff --git a/host/gifstream.py b/host/gifstream.py new file mode 100755 index 0000000..a580ae1 --- /dev/null +++ b/host/gifstream.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python3 +# This script eats CRAP and outputs a live GIF-over-HTTP stream. The required bandwidth is about 20kB/s + +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('