File size: 1,117 Bytes
2336cc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json

def create_json_dataset(prompt_file, video_file, output_file):
    with open(prompt_file, 'r', encoding='utf-8') as f_prompt, \
         open(video_file, 'r', encoding='utf-8') as f_video, \
         open(output_file, 'w', encoding='utf-8') as f_out:
        
        for caption, video_path in zip(f_prompt, f_video):
            # 去除两端的空白字符和换行符
            caption = caption.strip()
            video_path = video_path.strip()
            
            # 创建字典并转换为JSON字符串
            data = {
                "video_path": video_path,
                "caption": caption
            }
            json_str = json.dumps(data)
            
            # 写入输出文件
            f_out.write(json_str + '\n')

# 使用示例
prompt_file = '/mnt/workspace/checkpoints/Wild-Heart/Disney-VideoGeneration-Dataset/prompt.txt'
video_file = '/mnt/workspace/checkpoints/Wild-Heart/Disney-VideoGeneration-Dataset/videos.txt'
output_file = 'caption_video.json'

create_json_dataset(prompt_file, video_file, output_file)
print(f"JSON文件已生成: {output_file}")