SuperCS's picture
Add files using upload-large-folder tool
2336cc9 verified
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}")