User:Cristinac/Project01: Difference between revisions
No edit summary |
No edit summary |
||
Line 26: | Line 26: | ||
[[ffmpeg]] | [[ffmpeg]] | ||
including ffmpeg-commands within a python script: | |||
<source lang="python"> | |||
from PIL import Image | |||
import os | |||
# ***FROM VIDEO TO IMAGE*** | |||
a = "ffmpeg -i bambi.mpeg -f image2 -r 1 -an imgs2/image%04d.jpg -y" | |||
print a | |||
os.system(a) | |||
# ***SORTING IMAGES ON BRIGHTNESS (make grayscale, convert to 1x1px image, value the grayscaleness of this pixel) *** | |||
def avg(p): | |||
pil_im = Image.open(p) | |||
i=pil_im.convert('L') | |||
i.thumbnail((1,1)) | |||
g=i.getpixel((0,0)) | |||
return g | |||
from glob import glob | |||
imgs = glob("imgs2/*.jpg") | |||
imgs.sort() | |||
d = [] | |||
for x in imgs: | |||
d.append((avg(x), x)) | |||
d.sort() | |||
print d | |||
import shutil | |||
i=0 | |||
for g, image in d: | |||
newname='sorted/sorted{0:04d}.jpg'.format(i) | |||
print "copying", name, "to", newname | |||
shutil.copyfile(image, newname) | |||
i=i+1 | |||
# ***FROM IMAGES TO VIDEO*** | |||
b = "ffmpeg -f image2 -r 15 -i imgs2/image%04d.jpg -r 30 imgs2.mp4 -y" | |||
print b | |||
os.system(b) | |||
</source> |
Revision as of 17:33, 17 February 2015
Python script:
from PIL import Image
def avg(p):
pil_im = Image.open(p)
i=pil_im.convert('L')
i.thumbnail((1,1))
g=i.getpixel((0,0))
return g
from glob import glob
imgs = glob("*.jpeg")
imgs.sort()
d = []
for x in imgs:
d.append((avg(x), x))
d.sort()
print d
including ffmpeg-commands within a python script:
from PIL import Image
import os
# ***FROM VIDEO TO IMAGE***
a = "ffmpeg -i bambi.mpeg -f image2 -r 1 -an imgs2/image%04d.jpg -y"
print a
os.system(a)
# ***SORTING IMAGES ON BRIGHTNESS (make grayscale, convert to 1x1px image, value the grayscaleness of this pixel) ***
def avg(p):
pil_im = Image.open(p)
i=pil_im.convert('L')
i.thumbnail((1,1))
g=i.getpixel((0,0))
return g
from glob import glob
imgs = glob("imgs2/*.jpg")
imgs.sort()
d = []
for x in imgs:
d.append((avg(x), x))
d.sort()
print d
import shutil
i=0
for g, image in d:
newname='sorted/sorted{0:04d}.jpg'.format(i)
print "copying", name, "to", newname
shutil.copyfile(image, newname)
i=i+1
# ***FROM IMAGES TO VIDEO***
b = "ffmpeg -f image2 -r 15 -i imgs2/image%04d.jpg -r 30 imgs2.mp4 -y"
print b
os.system(b)