Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About the number of input video frames #36

Open
elvindp opened this issue Sep 25, 2024 · 1 comment
Open

About the number of input video frames #36

elvindp opened this issue Sep 25, 2024 · 1 comment

Comments

@elvindp
Copy link

elvindp commented Sep 25, 2024

Hi, when l use the example python api to inference a video with 15mins, it consume large GPU memory and report torch.cuda.OutOfMemoryError. I find the script "load_video" extract 1 frame per second, which need 900 frames for 15min video and cost large memory.
So is there any suggested number of input frames for long videos? for example, one video 30 frames?

@CarlCloudWang
Copy link

sample some frames per second...
def load_video(video_file, skip=1):
from decord import VideoReader
vr = VideoReader(video_file)

# Get video frame rate
fps = vr.get_avg_fps()

# Calculate frame indices for 1fps
frame_indices = [int(fps * i) for i in range(int(len(vr) / fps))]
frames = vr.get_batch(frame_indices).asnumpy()
ls = []

if skip == 1 or skip is None:
    ls = [Image.fromarray(frames[i]) for i in range(int(len(vr) / fps))]
elif skip > 1:
    ls = [Image.fromarray(frames[i]) for i in range(int(len(vr) / fps))][::skip]  # sample frame
elif skip < 0:
    ls = [Image.fromarray(frames[i]) for i in range(int(len(vr) / fps))][:-skip]  # skip<0 and get 0 to -skip frame

return ls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants