Skip to content

Instantly share code, notes, and snippets.

@marcan
Created December 30, 2015 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcan/2491f91cc6a99c37157c to your computer and use it in GitHub Desktop.
Save marcan/2491f91cc6a99c37157c to your computer and use it in GitHub Desktop.
Video player for the 32c3 flip-dot display
#!/usr/bin/python2
import sys, ffms, time, socket
import numpy as np
source_file = sys.argv[1]
# Output one out of every N frames
framedrop = 18
# Input video FPS (hardcoded)
fps = 30
# Output dimensions (this is a 4:3 letterboxed area). Keep even due to silly padding code below.
# This should match the video aspect ratio (otherwise video will be stretched)
W = 144
H = 108
# Real height of flipdot display
W2 = 144
H2 = 120
# Padding
PW= (W2-W)/2
PH = (H2-H)/2
vsource = ffms.VideoSource(source_file)
vsource.set_output_format([ffms.get_pix_fmt("gray")], width=W, height=H)
t = time.time()
dest = [
"2001:67c:20a1:1095:ba27:ebff:feb9:db12",
"2001:67c:20a1:1095:ba27:ebff:fe23:60d7",
"2001:67c:20a1:1095:ba27:ebff:fe71:dd32"
]
sock = socket.socket(socket.AF_INET6,
socket.SOCK_DGRAM)
for frameno in xrange(0, vsource.properties.NumFrames, framedrop):
data = vsource.get_frame(frameno).planes[0].reshape((H,W)).astype(float)
bits = np.pad(data > 128, [[PH,PH],[PW, PW]], mode="constant").astype("uint8")[::-1,:]
bits = np.packbits(bits, axis=0)
pkts = [p.tostring("F") for p in (bits[:,0:48], bits[:,48:96], bits[:,96:144])]
for p in pkts:
for i in range(48):
s = ""
for c in p[i*15:i*15+15]:
s += format(ord(c), '08b')
print s
for i, (d, p) in enumerate(zip(dest, pkts)):
sock.sendto(p, (d, 2323))
# Try to stagger updates of each third a bit. Comment out for coincident updates.
if i != 2:
time.sleep(0.5/3.1)
wt = t + frameno / float(fps)
nt = time.time()
if nt < wt:
time.sleep(wt-nt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment