nielsr HF staff commited on
Commit
caafb33
1 Parent(s): 8c404a8

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +34 -0
README.md ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This is the code that was used to generate this video:
2
+
3
+ ```
4
+ from decord import VideoReader, cpu
5
+ from huggingface_hub import hf_hub_download
6
+ import numpy as np
7
+
8
+ np.random.seed(0)
9
+
10
+ def sample_frame_indices(clip_len, frame_sample_rate, seg_len):
11
+ converted_len = int(clip_len * frame_sample_rate)
12
+ end_idx = np.random.randint(converted_len, seg_len)
13
+ start_idx = end_idx - converted_len
14
+ indices = np.linspace(start_idx, end_idx, num=clip_len)
15
+ indices = np.clip(indices, start_idx, end_idx - 1).astype(np.int64)
16
+ return indices
17
+
18
+ file_path = hf_hub_download(
19
+ repo_id="nielsr/video-demo", filename="eating_spaghetti.mp4", repo_type="dataset"
20
+ )
21
+ vr = VideoReader(file_path, num_threads=1, ctx=cpu(0))
22
+
23
+ # sample 8 frames
24
+ vr.seek(0)
25
+ indices = sample_frame_indices(clip_len=8, frame_sample_rate=1, seg_len=len(vr))
26
+ buffer = vr.get_batch(indices).asnumpy()
27
+
28
+ # create a list of NumPy arrays
29
+ video = [buffer[i] for i in range(buffer.shape[0])]
30
+
31
+ video_numpy = np.array(video)
32
+ with open('spaghetti_video_8_frames.npy', 'wb') as f:
33
+ np.save(f, video_numpy)
34
+ ```