Splitting video into frames in python

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
Posts: 62
Joined: Mon Sep 10, 2007 8:39 am UTC
Location: Mid North SA, Australia

Splitting video into frames in python

Postby abrenecki » Thu Aug 28, 2008 9:44 am UTC

I have a short video (1.2s) which i want to turn into a multiple-flash-photo type thing. I have a fairly good idea how I will do this, but first I need to extract frames from the video. Ideally, I want some sort of module that can do this sort of thing:

Code: Select all

image = video.GetFrame(123)

and I have these requirements:
  • Works on Windows and Mac (I have Xcode, gcc, and ffmpeg)
  • Works with .m4v files (exported by iMovie) and .wmv files (exported by Windows Movie Maker)
  • Isn't pyffmpeg (badly supported, doesn't compile even after patches from the issue tracker are applied)
Alternatively, something that can do this:

Code: Select all

ffmpeg -i 1.1.m4v -vcodec png -r 5 -an -f image2 1.1.%03d.png

but in a cross-platform fashion would be good.
I've done some googling, but I've had enough after trying to get ffmpeg to work.
I'm new to Python, and new to video stuff, so sorry if I've overlooked something obvious.
Full disclosure: This is for a practical in SACE Stage 2 Physics. However, the code I'm writing is not a part of the practical (I'm trying to emulate a multriple-flash camera from a video, the code won't be assessed) and this is only a small part of the code (extracting the images so I can manipulate them).

User avatar
Posts: 281
Joined: Thu Dec 06, 2007 2:17 am UTC
Location: Melbourne, AU

Re: Splitting video into frames in python

Postby r1chard » Thu Aug 28, 2008 11:42 am UTC

Look into avbin and its Python bindings in pyglet.

AVBin is a stable-ABI and shared-linking-friendly wrapper around ffmpeg (why library authors can't bother to produce their own stable ABI is beyond me) and I believe you'll be able to extract single frames using it.

Return to “Coding”

Who is online

Users browsing this forum: No registered users and 8 guests