Experiment with video 1: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
Breaking down movies. <br /> | Breaking down movies. <br /> | ||
I. Extracting 1 frame per second from video using FFMPEG encoder. <br /> | |||
In terminal: <br /> | |||
~user$ ffmpeg -i experiment/video.mp4 -r 1 experiment/frames/frame%04d.png<br /> | |||
II. Extracting 1 pixel wide line from the frames and combining them in one PNG-file. | |||
<source lang="python"> | <source lang="python"> |
Latest revision as of 15:01, 12 January 2016
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()