[Tutor] Reading a video

Jim Mooney cybervigilante at gmail.com
Fri Aug 16 10:01:38 CEST 2013


http://code.google.com/p/pyffmpeg/

PyFFmpeg has stayed in minimal status where it could be used to
extract individual frames from video files and create PIL image
objects from them.

While there were several Python libraries that offer to play video
files most of them did not provide any API to extract individual
frames, and this is the reason PyFFmpeg was created.


Jim

On 15 August 2013 20:53, Steven D'Aprano <steve at pearwood.info> wrote:
> On 15/08/13 23:54, Zoya Tavakkoli wrote:
>>
>> Hi
>> How can read a video frame by frame in python?
>
>
> Of course! Videos are just binary files, and Python can read binary files.
> The hard part is writing code that understands the internal structure of a
> video. There are many video formats (ogv, mp4, mov, avi, flv, mpg, asf, wmv,
> ram, to name just a few), and the internal structure of them will be
> different and not always documented anywhere, which may mean you have to
> reverse-engineer the format.
>
> Doing this in pure Python code will likely be slow, unless you use an
> optimizing compiler like PyPy.
>
> Your best best is to look for a library that already understands video
> formats. If there is no pre-existing Python library, there may be a C
> library with a Python interface. Of you can create your own Python
> interface, maybe using ctypes to talk to the library.
>
> But honestly, it's probably a huge amount of work for something that will
> likely be rather slow, unless you use PyPy, in which case it will just be a
> huge amount of work. It will be less work if you only care about one video
> format.
>
> What are you hoping to do with the frames once you get them? You may be
> better off using an external application like mplayer or ffmpeg to extract
> the frames to (say) png files, and then manipulate the images from Python,
> perhaps using PIL or similar.
>
>
> --
> Steven
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



-- 
Jim

"If you don't know it's impossible, it's easier to do." --Neil Gaiman
"The Process is not the Picture...Reality can only be proved to be
weakly-objective. Strong objectivity is a myth." --Bernardo Kastrup
"You cannot use logic to justify logic, so logic itself has no basis
other than faith." --Agrippa


More information about the Tutor mailing list