Hello, Is there a way to read frames of a movie in python? Ideally, something as simple as: for frame in movie('mymovie.mov'): pass where frame is either a 2-D list, or a numpy array? The movie format can be anything, because I can probably convert things, but most convenient would be avi, mov, and flv (for youtube videos). thanks, Brian Blais -- Brian Blais bblais@bryant.edu http://web.bryant.edu/~bblais
On Dienstag 29 Januar 2008, Brian Blais wrote:
Is there a way to read frames of a movie in python? Ideally, something as simple as:
for frame in movie('mymovie.mov'): pass
where frame is either a 2-D list, or a numpy array? The movie format can be anything, because I can probably convert things, but most convenient would be avi, mov, and flv (for youtube videos).
I'd look for Gstreamer python bindings. Or run mplayer/mencoder with a "raw" format (e.g. yuv4mpeg or -ovc raw -vf format=bgr24/rgb15/...) using a pipe and processing the frames one by one. OK, that's no iterator-based interface yet, but one could probably hack that together in an hour or so. Ciao, / / .o. /--/ ..o / / ANS ooo
I'd sugget pyglet's avbin library. Hans Meine wrote:
On Dienstag 29 Januar 2008, Brian Blais wrote:
Is there a way to read frames of a movie in python? Ideally, something as simple as:
for frame in movie('mymovie.mov'): pass
where frame is either a 2-D list, or a numpy array? The movie format can be anything, because I can probably convert things, but most convenient would be avi, mov, and flv (for youtube videos).
I'd look for Gstreamer python bindings. Or run mplayer/mencoder with a "raw" format (e.g. yuv4mpeg or -ovc raw -vf format=bgr24/rgb15/...) using a pipe and processing the frames one by one. OK, that's no iterator-based interface yet, but one could probably hack that together in an hour or so.
Ciao, / / .o. /--/ ..o / / ANS ooo
------------------------------------------------------------------------
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
On Jan 29, 2008, at Jan 29:8:24 PM, Andrew Straw wrote:
I'd suggest pyglet's avbin library.
great suggestion! I never would have thought to do that. Do you happen to know how to convert a player.texture into a numpy.array? there is ImageData, but I can't seem to figure out how to do the conversion. bb -- Brian Blais bblais@bryant.edu http://web.bryant.edu/~bblais
I'm pretty sure there's code floating around the pyglet mailing list. I'd be happy to add it to http://code.astraw.com/projects/motmot/wiki/pygarrayimage if it seems reasonable. (pygarrayimage goes from numpy array to pyglet texture). Brian Blais wrote:
On Jan 29, 2008, at Jan 29:8:24 PM, Andrew Straw wrote:
I'd suggest pyglet's avbin library.
great suggestion! I never would have thought to do that. Do you happen to know how to convert a
player.texture into a numpy.array?
there is ImageData, but I can't seem to figure out how to do the conversion.
bb -- Brian Blais bblais@bryant.edu <mailto:bblais@bryant.edu> http://web.bryant.edu/~bblais <http://web.bryant.edu/%7Ebblais>
------------------------------------------------------------------------
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
On Jan 29, 2008, at Jan 29:9:25 PM, Andrew Straw wrote:
I'm pretty sure there's code floating around the pyglet mailing list. I'd be happy to add it to http://code.astraw.com/projects/motmot/wiki/pygarrayimage if it seems reasonable. (pygarrayimage goes from numpy array to pyglet texture).
I checked the pyglet users group, and the only mention I see is from: http://groups.google.com/group/pyglet-users/browse_thread/thread/ 5981f764902c7df/888328e19653be1a?lnk=gst&q=numpy#888328e19653be1a there, he has the solution: a = numpy.frombuffer(surf_clip.get_data(), numpy.uint8) a.shape = (sw, sh, 4) a = a[:,:,0:3] #drop alpha channel but when I do it (see code below) the image is clearly munged, so I think the decoding is not quite right. any ideas? thanks, Brian Blais -- Brian Blais bblais@bryant.edu http://web.bryant.edu/~bblais import pylab import numpy from pyglet import media,window win = window.Window(resizable=True) player = media.Player() filename='ica_mvl.avi' # from http://hlab.phys.rug.nl/demos/ica/ jiminy.html source = media.load(filename) player.queue(source) player.play() if True: player.dispatch_events() imdata=player.texture.get_image_data() a = numpy.frombuffer(player.texture.get_image_data().data, numpy.uint8) a.shape = (imdata.width, imdata.height, 4) a = a[:,:,0:3] #drop alpha channel # make gray im=a.sum(axis=1)/3 pylab.imshow(im,cmap=pylab.cm.gray) pylab.show() pylab.draw()
participants (3)
-
Andrew Straw
-
Brian Blais
-
Hans Meine