[Python] Number of frames in a video using PyAV

Discussão em 'Python' iniciado por Stack, Fevereiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I use the library PyAV because it's one of the fatest available with Python.

    Here is a simple example of code I would like to use:

    import av

    video = av.open("My_Super_Video.mp4")

    total_frames = # ????

    for i, frame in enumerate(video.decode(video=0)):
    img = frame.to_image() # PIL image

    print("Frame: %d/%d ..." % (i, total_frames))


    I could obviously use other libraries to load the library, however I would prefer using PyAV if possible due to its processing speed.

    Question 1: Is it possible to obtain the number of frames with PyAV ? If yes, how ?

    Question 2: In the case, I would consider using another library to load and process the video frame by frame. Which library would allow me to do the above with the highest speed as possible. I know the followings, but don't know how they compare:

    1. PIMS On top of PyAV, could add some interesting feature ?
    2. MoviePy (limited to videos which fit in RAM), but what about perf ?
    3. Imageio (probably same limitation as above), but what about perf ?
    4. OpenCV (probably same limitation as above), but what about perf ?
    5. Others ?

    Continue reading...

Compartilhe esta Página