File size: 1,210 Bytes
19fe404
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import argparse
import json
import os

def parse_args():
    parser = argparse.ArgumentParser(description="Convert jsonl to json.")
    parser.add_argument("--video_folder", type=str, default="", help="The video folder.")
    parser.add_argument(
        "--jsonl_load_path", type=str, default=None, help="The path to the video dataset metadata (csv/jsonl)."
    )
    parser.add_argument("--save_path", type=str, default=None, help="The save path to the output results.")
    args = parser.parse_args()
    return args

def main():
    args = parse_args()

    with open(args.jsonl_load_path, "r") as read:
        _lines = read.readlines()

    output = []
    for line in _lines:
        try:
            line = json.loads(line.strip())
            videoid, name = line['video_path'], line['summary_caption']
            output.append(
                {
                    "file_path": os.path.join(args.video_folder, videoid),
                    "text": name,
                    "type": "video",
                }
            )
        except:
            pass

    with open(args.save_path, mode="w", encoding="utf-8") as f:
        json.dump(output, f, indent=2)

if __name__ == "__main__":
    main()