2011-01-26 13 views
7

Come può Python creare un semplice cappuccio per un video.Genera automaticamente la miniatura CAP per il piccolo video

Ideia: prendere 9 istantanee per 9 posti anche (sulla timeline) volte, e spostare poi in un JGP

Come posso fare questo?

PIL è l'unico modo? (Non sarà facile fare quello che voglio, giusto?)

non ci sono alcun modulo (python seens avere grande modeles per almoust nulla, o sono io fuori di fortuna)

Esempio:

Movie lenght = 10 min 
T1= snapshot of 1 min 
T2= snapshot of 2 min 
...... 
T9= snapshot of 9 min 
    | | 
T1| T2| T3 
---+---+--- 
T4| T5| T6 
---+---+--- 
T7| T8| T9 
    | | 

risposta

7

si tratta di un rapido cambio di qualcosa che ho fatto qualche tempo fa, utilizzando ffmpeg per l'estrazione telaio e PIL per creare l'immagine completa pollici.

import os, sys 
from PIL import Image 

# Use "ffmpeg -i <videofile>" to get total length by parsing the error message 
chout, chin, cherr = os.popen3("ffmpeg -i %s" % sys.argv[1]) 
out = cherr.read() 
dp = out.index("Duration: ") 
duration = out[dp+10:dp+out[dp:].index(",")] 
hh, mm, ss = map(float, duration.split(":")) 
total = (hh*60 + mm)*60 + ss 

# Use "ffmpeg -i <videofile> -ss <start> frame<nn>.png" to extract 9 frames 
for i in xrange(9): 
    t = (i + 1) * total/10 
    os.system("ffmpeg -i %s -ss %0.3fs frame%i.png" % (sys.argv[1], t, i)) 

# Make a full 3x3 image by pasting the snapshots 
full = None 
for y in xrange(3): 
    for x in xrange(3): 
     img = Image.open("frame%i.png" % (y*3+x)) 
     w, h = img.size 
     if full is None: 
      full = Image.new("RGB", (w*3, h*3)) 
     full.paste(img, (x*w, y*h)) 

# Save result 
full.save("thumbs.png") 
+0

Lo proverò stasera. Wow commenta il tuo codice (THANX :)) –

Problemi correlati