hf-internal-testing/spaghetti-video-8-frames
收藏数据集概述
数据集内容
- 数据集包含一个名为 "eating_spaghetti.mp4" 的视频文件。
- 该视频文件被用于生成一个包含8帧的NumPy数组,存储在 "spaghetti_video_8_frames.npy" 文件中。
数据处理方法
- 使用
decord库读取视频文件。 - 通过
huggingface_hub库从 "nielsr/video-demo" 仓库下载视频文件。 - 使用随机种子
0生成帧索引。 - 从视频中采样8帧,并将这些帧存储为NumPy数组。
代码示例
python 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, end_idx - 1).astype(np.int64) return indices
file_path = hf_hub_download( repo_id="nielsr/video-demo", filename="eating_spaghetti.mp4", repo_type="dataset" ) vr = VideoReader(file_path, num_threads=1, ctx=cpu(0))
sample 8 frames
vr.seek(0) indices = sample_frame_indices(clip_len=8, frame_sample_rate=1, seg_len=len(vr)) buffer = vr.get_batch(indices).asnumpy()
create a list of NumPy arrays
video = [buffer[i] for i in range(buffer.shape[0])]
video_numpy = np.array(video) with open(spaghetti_video_8_frames.npy, wb) as f: np.save(f, video_numpy)



