-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (30 loc) · 1.34 KB
/
main.py
File metadata and controls
41 lines (30 loc) · 1.34 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 argparse
import json
import os
import cv2
from detector import AvatarDetector
from srt_writer import generate_srt
def main():
parser = argparse.ArgumentParser(description="Generate SRT subtitles from avatar activity in video.")
parser.add_argument('config_file', help="Path to JSON configuration file.")
parser.add_argument('--video', help="Path to video file (overrides config).")
parser.add_argument('--output', help="Path to output directory for SRT files (overrides config).")
args = parser.parse_args()
if not os.path.exists(args.config_file):
print(f"Error: Config file '{args.config_file}' not found.")
return
with open(args.config_file, 'r') as f:
config = json.load(f)
video_path = args.video if args.video else config.get('source_video', 'test_video.mp4')
output_path = args.output if args.output else config.get('output_dir', 'output')
if not os.path.exists(video_path):
print(f"Error: Video file '{video_path}' not found.")
return
print(f"Processing {video_path}...")
detector = AvatarDetector(video_path, config['speakers'], config)
detector.process_video()
segments = detector.analyze_segments()
generate_srt(segments, output_path, config)
print("Done.")
if __name__ == "__main__":
main()