Created
October 7, 2018 16:35
-
-
Save lukas2511/97f5f2c8f9072beda3bfe2ee8afbb4db to your computer and use it in GitHub Desktop.
play any videos (even livestreams!) on the weird service-point led matrix display in cccb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
import bz2 | |
import numpy as np | |
from PIL import Image | |
import socket | |
import time | |
import sys | |
import tqdm | |
import os | |
import glob | |
HOST, PORT = "172.23.42.29", 2342 | |
CMD_LED_DRAW = 18 | |
def resize_image(img, size, blackbg=True): | |
tw, th = size | |
w, h = img.size | |
a, b = w/tw, h/th | |
f = 1/max(a, b) | |
pos = int((tw-w*f)/2), int((th-h*f)/2) | |
buf = Image.new('RGBA', (tw, th)) | |
buf.paste(img.resize((int(w*f), int(h*f))).convert('RGBA'), pos) | |
if blackbg: | |
buf2 = Image.new('RGBA', (tw, th), (0, 0, 0, 255)) | |
return Image.alpha_composite(buf2, buf) | |
else: | |
return buf | |
def do_gamma(im, gamma): | |
"""Fast gamma correction with PIL's image.point() method""" | |
invert_gamma = 1.0/gamma | |
lut = [pow(x/255., invert_gamma) * 255 for x in range(256)] | |
lut = lut*4 # need one set of data for each band for RGBA | |
im = im.point(lut) | |
return im | |
def calcframe(img): | |
displaysize = (56*8, 8*20) | |
frame = np.frombuffer(do_gamma(resize_image(img, displaysize), 0.5).convert('1').tobytes(), dtype='1b') | |
return struct.pack('!HHHHH', CMD_LED_DRAW, 0, 0, 0x627a, 0) + bz2.compress(frame) | |
#sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
#if len(sys.argv[1:]) > 1: | |
# frames = [] | |
# for arg in tqdm.tqdm(sys.argv[1:]): | |
# frames.append(calcframe(Image.open(arg))) | |
# | |
# while True: | |
# for frame in frames: | |
# sock.sendto(frame, (HOST, PORT)) | |
# time.sleep(0.04) | |
#else: | |
# sock.sendto(calcframe(Image.open(sys.argv[1])), (HOST, PORT)) | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
while True: | |
for frame in sorted(glob.glob("/tmp/frames/frame*.png"))[:-1]: | |
sock.sendto(calcframe(Image.open(frame)), (HOST, PORT)) | |
os.unlink(frame) | |
time.sleep(0.01) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
playvideo() { | |
killall ffmpeg | |
sleep 0.2 | |
rm -f /tmp/frames/frame*.png | |
ffmpeg -re -y -i "${1}" -s 448x160 -an -r 25 '/tmp/frames/frame%05d.png' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment