简体   繁体   中英

How to set fps in python decord library?

package link : https://github.com/dmlc/decord

I am using decord to extract frames and it does a good job, by default it uses video fps. Lets say i need to extract frame at 0.2 fps.

example : i have a video at 48 seconds and its fps is 30. when i extract i get 1440 frames

But, I need to specify the fps like 0.2 so , the output should be 10 frames.

PS. In ffmpeg, we can specify the fps while extracting. I am asking in the same way.

My code:

from decord import VideoReader
from matplotlib import pyplot as plt

vr = VideoReader("nature.mp4")
vr._avg_fps = 0.2  ##Not worked
for i in range(len(vr)):
    frame = vr[i].asnumpy()
    plt.imsave(f'{name}_Frame_{i}.jpg',frame)

Help appreciated

maybe you can skip frame like this:

from decord import VideoReader
from matplotlib import pyplot as plt

vr = VideoReader("nature.mp4")
avg_fps = 0.2
for i in range(0, 1500, int(30/min(30,avg_fps))):
    frame = vr[i].asnumpy()
    plt.imsave(f'{name}_Frame_{i}.jpg',frame)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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