(video_path, num_frames, sample='rand', fix_start=None, clip=None, min_num_frames=4)
| 61 | |
| 62 | |
| 63 | def 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 | |
| 87 | def extract_frame_number(filename): |
nothing calls this directly
no test coverage detected