简体   繁体   English

使用 PyAV 的视频中的帧数

[英]Number of frames in a video using PyAV

I use the library PyAV because it's one of the fatest available with Python.我使用 PyAV 库,因为它是 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.我显然可以使用其他库来加载库,但是如果可能的话,我更喜欢使用 PyAV,因为它的处理速度。

Question 1: Is it possible to obtain the number of frames with PyAV ?问题 1:是否可以使用 PyAV 获取帧数? If yes, how ?如果是,如何?

Question 2: In the case, I would consider using another library to load and process the video frame by frame.问题2:在这种情况下,我会考虑使用另一个库来逐帧加载和处理视频。 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 ? PIMS在 PyAV 之上,可以添加一些有趣的功能吗?
  2. MoviePy (limited to videos which fit in RAM), but what about perf ? MoviePy (仅限于适合 RAM 的视频),但是 perf 呢?
  3. Imageio (probably same limitation as above), but what about perf ? Imageio (可能与上述限制相同),但是 perf 呢?
  4. OpenCV (probably same limitation as above), but what about perf ? OpenCV (可能与上述限制相同),但是 perf 呢?
  5. Others ?其他的 ?

To get the frames of the first video stream do:要获取第一个视频流的帧,请执行以下操作:

container = av.open("My_Super_Video.mp4")
total_frames = container.streams.video[0].frames

You can get the number of frames in stream with Stream.frames attribute.您可以使用 Stream.frames 属性获取流中的帧数。

Source: http://docs.mikeboers.com/pyav/develop/api/stream.html#av.stream.Stream来源: http : //docs.mikeboers.com/pyav/develop/api/stream.html#av.stream.Stream

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM