MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / read_frames_decord

Function read_frames_decord

data/video_utils.py:63–84  ·  view source on GitHub ↗
(video_path, num_frames, sample='rand', fix_start=None, clip=None, min_num_frames=4)

Source from the content-addressed store, hash-verified

61
62
63def read_frames_decord(video_path, num_frames, sample='rand', fix_start=None, clip=None, min_num_frames=4):
64 video_reader = decord.VideoReader(video_path, num_threads=1)
65 vlen = len(video_reader)
66 fps = video_reader.get_avg_fps()
67 duration = vlen / float(fps)
68 if clip:
69 start, end = clip
70 duration = end - start
71 vlen = int(duration * fps)
72 start_index = int(start * fps)
73
74 t_num_frames = np.random.randint(min_num_frames, num_frames + 1)
75
76 frame_indices = get_frame_indices(
77 t_num_frames, vlen, sample=sample, fix_start=fix_start,
78 input_fps=fps
79 )
80 if clip:
81 frame_indices = [f + start_index for f in frame_indices]
82 frames = video_reader.get_batch(frame_indices).asnumpy() # (T, H, W, C), np.uint8
83 frames = [Image.fromarray(frames[i]) for i in range(frames.shape[0])]
84 return frames
85
86
87def extract_frame_number(filename):

Callers

nothing calls this directly

Calls 1

get_frame_indicesFunction · 0.85

Tested by

no test coverage detected