J'ai utilisé ce script pour convertir un film à un tableau numpy + binaire magasin:
"""
Takes a MPEG movie and produces a numpy record file with a numpy array.
"""
import os
filename = 'walking'
if not(os.path.isfile(filename + '.npy')): # do nothing if files exists
N_frame = 42 # number of frames we want to store
os.system('ffmpeg -i WALK.MOV.qt -f image2 foo-%03d.png')
# convert them to numpy
from numpy import zeros, save, mean
from pylab import imread
n_x, n_y, n_rgb = imread('foo-001.png').shape
mov = zeros((n_y, n_x, N_frame))
for i_frame in range(N_frame):
name = 'foo-%03d.png' % (i_frame +1)
mov[:n_y,:n_x,i_frame] = flipud(mean(imread(name), axis=2)).T
os.system('rm -f foo-*.png')
save(filename + '.npy', mov)
Notez que selon vos conventions, vous voudrez peut-être pas retourner l'image. vous pouvez ensuite le charger en utilisant:
load('walking.npy')
Bien que ce soit ancien, j'ai un code Python qui prend un nom de fichier et retourne un itérateur d'images PIL. Je peux poster le code source si quelqu'un est intéressé. – carl