Repository navigation
Expand file tree
/
Copy pathcreate_metadata.py
More file actions
61 lines (46 loc) · 2.23 KB
/
Copy pathcreate_metadata.py
File metadata and controls
61 lines (46 loc) · 2.23 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import pandas as pd
import os
def create_metadata_csv(videos_file_path, captions_file_path, output_csv_path):
"""
Create a metadata.csv file combining video filenames with their corresponding captions.
Args:
videos_file_path: Path to the videos.txt file containing video filenames
captions_file_path: Path to the prompt.txt file containing captions
output_csv_path: Path where the metadata.csv file will be saved
"""
# Read video filenames
with open(videos_file_path, 'r', encoding='utf-8') as f:
video_filenames = [line.strip() for line in f if line.strip()]
# Read captions
with open(captions_file_path, 'r', encoding='utf-8') as f:
captions = [line.strip() for line in f if line.strip()]
# Verify that we have the same number of videos and captions
if len(video_filenames) != len(captions):
print(f"Warning: Number of video files ({len(video_filenames)}) doesn't match number of captions ({len(captions)})")
min_length = min(len(video_filenames), len(captions))
video_filenames = video_filenames[:min_length]
captions = captions[:min_length]
print(f'Using first {min_length} entries for both')
# Create DataFrame
metadata_df = pd.DataFrame({
'video': video_filenames,
'prompt': captions
})
# Save to CSV
metadata_df.to_csv(output_csv_path, index=False, encoding='utf-8')
print(f'Created metadata.csv with {len(metadata_df)} entries')
print(f'Saved to: {output_csv_path}')
# Display first few entries
print('\nFirst 5 entries:')
print(metadata_df.head())
return metadata_df
if __name__ == "__main__":
dataset_dir = '/opt/liblibai-models/user-workspace2/users/qyl/datasets/Disney-VideoGeneration-Dataset'
videos_file = os.path.join(dataset_dir, 'videos.txt')
captions_file = os.path.join(dataset_dir, 'prompt.txt')
output_csv = os.path.join(dataset_dir, 'metadata.csv')
if not os.path.exists(videos_file):
raise FileNotFoundError(f"videos.txt not found at: {videos_file}")
if not os.path.exists(captions_file):
raise FileNotFoundError(f"prompt.txt not found at: {captions_file}")
create_metadata_csv(videos_file, captions_file, output_csv)