Skip to content

Instantly share code, notes, and snippets.

@crowsonkb
Last active August 29, 2015 14:03
Show Gist options
  • Save crowsonkb/1329b0ba25b4547dd4b6 to your computer and use it in GitHub Desktop.
Save crowsonkb/1329b0ba25b4547dd4b6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import numpy as np
import sys
FRAME_SIZE = 1920*1080*3
BPC = 2
MAXINT = (256**BPC) - 1
GAMMA = 2.0 # A much faster approximation than 2.2
accum = np.zeros(FRAME_SIZE, dtype='f4')
count = 0
while True:
data = sys.stdin.read(FRAME_SIZE*BPC)
if len(data) < FRAME_SIZE*BPC:
break
frame = np.fromstring(data, dtype='<u2')
accum += (frame.astype('f4')/MAXINT)**GAMMA
count += 1
accum /= count
accum **= 1/GAMMA
accum *= 65535
accum.astype('<u2').tofile(sys.stdout)
ffmpeg -i BDMV.mov -f rawvideo -sws_flags print_info -vf format=yuv444p -pix_fmt rgb48le - | ./blend.py | ffmpeg -f rawvideo -pixel_format rgb48le -video_size 1920x1080 -i - out.tiff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment