Vikesh
Vikesh

Reputation: 2028

Decoding multiple video streams in Python process address space

I am working on a project that requires decoding a large number of videos (say ~50, each with HD resolution) and use the raw pixel values as numpy arrays in a Python process. The decoding should be near-real time (say 4-5 fps). What is a good way to do this efficiently? We can perform GPU accelerated decoding as well. The goal is to decode multiple videos concurrently so that the raw pixel values can later be processed by a Python process.

Upvotes: 0

Views: 751

Answers (1)

sascha
sascha

Reputation: 33532

So one approach is to use some decoder which is interfaced by python (no decode -> pipe -> python-process approach).

There are two common libraries to try:

Both use ffmpeg internally to decode your video (very efficiently). For both it's easy to read the stream then and put the pixels into some numpy array.

I did use MoviePy once to do this like seen here.

A condensed example (not tried):

from moviepy.editor import VideoFileClip
filepath = "output.avi"
clip = VideoFileClip(filepath)

for f in clip.iter_frames(progress_bar=True):
    np_array_frame = f

See also the docs of iter_frames.

Excerpt from the docs:

Iterates over all the frames of the clip.

Returns each frame of the clip as a HxWxN np.array,
 where N=1 for mask clips and N=3 for RGB clips.

Upvotes: 2

Related Questions