Skip to content

Speed up iter_frames with resized problem #2538

@houzeyu2683

Description

@houzeyu2683

I try to speed up iter_frames in my script, my idea is resize the video to smaller size before iter_frames, but I found it is more slow, here is my code and the running time:

path = 'storage/PLmVlUjKuEG7Qkg8ipBRol7MFmgQ_HK0tl/video/_8tZJnFJ7Sc.mp4'
video = moviepy.VideoFileClip(path)
video = video.resized(1)
print(f"Size: {video.size}")
total = int((video.duration * video.fps))

start = time.time()
iteration = enumerate(video.iter_frames(with_times=True), 1)
for index, (timestep, frame) in iteration:
    print(f"Progress: [{index}/{total}]", end='\r')
    continue
_ = iteration
end = time.time()
print("")
print(end-start)
# Size: (1920, 1080)
# Progress: [18225/18225]
# 195.89423060417175

path = 'storage/PLmVlUjKuEG7Qkg8ipBRol7MFmgQ_HK0tl/video/_8tZJnFJ7Sc.mp4'
video = moviepy.VideoFileClip(path)
video = video.resized(0.5)
print(f"Size: {video.size}")
total = int((video.duration * video.fps))

start = time.time()
iteration = enumerate(video.iter_frames(with_times=True), 1)
for index, (timestep, frame) in iteration:
    print(f"Progress: [{index}/{total}]", end='\r')
    continue
_ = iteration
end = time.time()
print("")
print(end-start)
# Size: (960, 540)
# Progress: [18225/18225]
# 642.015567779541

The first method is using the original video size in the iter_frames, the second one is resized to half in the iter_frames.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lib-FFmpegIssues pertaining to dependency FFmpeg.questionQuestions regarding functionality, usagevideoRelated to VideoClip and related classes, or handling of video in general.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions