For my project I want to extract frames from a video to make thumbnails. However every method i find is super slow going through the entere video. Here is what I have tried:
with iio.imopen(v.file.path, "r") as vObj:
metadata = iio.immeta(v.file.path, exclude_applied=False)
frame_num = int(metadata['fps']*metadata['duration']-metadata['fps'])
for i in range(10):
x = int((frame_num/100)*(i*10))
frame = vObj.read(index=x)
path = v.get_thumbnail_path(index=i)
os.makedirs(os.path.dirname(path), exist_ok=True)
iio.imwrite(path, frame)
logger.info('Written video thumbnail: {}'.format(path))
For a long video that takes extremely long. I know videos are compressed over multiple frames, however if I just manually open a video and jump to a point it also does not require to go through the video from first to last frame.
I don't care about specific frames, just roughly 10%, so sticking to keyframes is fine, if it makes it faster.
How to grab a frame every 10% of the video quickly?
Thank you.