Experiment with video 1

From XPUB & Lens-Based wiki

Breaking down movies.

I. Extracting 1 frame per second from video using FFMPEG encoder.
In terminal:
~user$ ffmpeg -i experiment/video.mp4 -r 1 experiment/frames/frame%04d.png

II. Extracting 1 pixel wide line from the frames and combining them in one PNG-file.

from glob import glob
from PIL import Image
import os, sys
from cStringIO import StringIO
n = 0
pixel_lines = []

ff = glob("frames/*")
ff.sort()
for f in ff:
	im = Image.open(f)
	x , y = im.size
	box = (x / 2, 0, (x / 2 + 1), y)
	region = im.crop(box)
	pixel_lines.append(region)

newim = Image.new('RGB', (len(ff),y))

print len(pixel_lines)

for pixel in pixel_lines:
	while n < len(pixel_lines):
		newim.paste(pixel_lines[n], (n, 0, n + 1, y))
		n = n + 1
newim.save('final.png')
newim.show()