-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_sequences.py
More file actions
41 lines (34 loc) · 1.45 KB
/
create_sequences.py
File metadata and controls
41 lines (34 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import shutil
def create_sequences(frame_dir, output_dir, sequence_length=5):
"""
Organize extracted frames into sequences.
Args:
frame_dir (str): Directory containing extracted frames.
output_dir (str): Directory to save organized sequences.
sequence_length (int): Number of frames per sequence.
"""
os.makedirs(output_dir, exist_ok=True)
for video_folder in os.listdir(frame_dir):
video_path = os.path.join(frame_dir, video_folder)
if not os.path.isdir(video_path):
continue
frames = sorted(os.listdir(video_path))
if len(frames) < sequence_length:
print(f"Skipping {video_folder} (not enough frames for a sequence).")
continue
video_output_dir = os.path.join(output_dir, video_folder)
os.makedirs(video_output_dir, exist_ok=True)
for i in range(0, len(frames) - sequence_length + 1, sequence_length):
sequence_dir = os.path.join(video_output_dir, f"sequence_{i // sequence_length:03d}")
os.makedirs(sequence_dir, exist_ok=True)
for j in range(sequence_length):
frame_path = os.path.join(video_path, frames[i + j])
shutil.copy(frame_path, os.path.join(sequence_dir, f"frame_{j:03d}.jpg"))
print('Done!')
# Example Usage
"""
frame_dir = "./Frames/Fake"
output_dir = "./LSTMDataset/Train/Fake"
create_sequences(frame_dir, output_dir, sequence_length=5)
"""