hf-internal-testing/spaghetti-video-8-frames
This is the code that was used to generate this video: from decord import VideoReader, cpu from huggingface_hub import hf_hub_download import numpy as np np.random.seed(0) def sample_frame_indices(clip_len, frame_sample_rate, seg_len): converted_len = int(clip_len * frame_sample_rate) end_idx = np.random.randint(converted_len, seg_len) start_idx = end_idx - converted_len indices = np.linspace(start_idx, end_idx, num=clip_len) indices = np.clip(indices, start_idx… See the full description on the dataset page: https://huggingface.co/datasets/hf-internal-testing/spaghetti-video-8-frames.
037
1---2---3 4This is the code that was used to generate this video:5 6```7from decord import VideoReader, cpu8from huggingface_hub import hf_hub_download9import numpy as np10 11np.random.seed(0)12 13def sample_frame_indices(clip_len, frame_sample_rate, seg_len):14 converted_len = int(clip_len * frame_sample_rate)15 end_idx = np.random.randint(converted_len, seg_len)16 start_idx = end_idx - converted_len17 indices = np.linspace(start_idx, end_idx, num=clip_len)18 indices = np.clip(indices, start_idx, end_idx - 1).astype(np.int64)19 return indices20 21file_path = hf_hub_download(22 repo_id="nielsr/video-demo", filename="eating_spaghetti.mp4", repo_type="dataset"23)24vr = VideoReader(file_path, num_threads=1, ctx=cpu(0))25 26# sample 8 frames27vr.seek(0)28indices = sample_frame_indices(clip_len=8, frame_sample_rate=1, seg_len=len(vr))29buffer = vr.get_batch(indices).asnumpy()30 31# create a list of NumPy arrays32video = [buffer[i] for i in range(buffer.shape[0])]33 34video_numpy = np.array(video)35with open('spaghetti_video_8_frames.npy', 'wb') as f:36 np.save(f, video_numpy)37```