-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
46 lines (37 loc) · 1.92 KB
/
main.py
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
import argparse
import os
from scene_extractor import extract_frames
from scene_matcher import match_scenes
from subs_maker import make_subs
from subs_mapper import match_subs_to_pages
import shutil
def main():
parser = argparse.ArgumentParser(description='Process some files.')
parser.add_argument('-v', '--video', help='Video file', required=True)
parser.add_argument('-d', '--document', help='PDF Document', required=True)
parser.add_argument('-s', '--subs', help='Subs file in VTT format. If not provided, it will be generated.')
parser.add_argument('-t', '--threshold', type=float, default=0.05, help='Threshold for scene detection')
parser.add_argument('-o', '--output', help='Output file saved in "output/". Default is "output.tex".')
args = parser.parse_args()
working_dir = "tmp/"
output_dir = "output/"
os.makedirs(working_dir, exist_ok=True)
os.makedirs(output_dir, exist_ok=True)
video_file = args.video
pdf_file = args.document
subs_file = args.subs if args.subs else make_subs(filename = video_file) # If subs file is not provided, generate it
threshold = args.threshold
out_file = output_dir + (args.output if args.output else "output.tex") # If output file is not provided, save it as "output.tex"
frame_dict = extract_frames(filename = video_file, threshold = threshold)
page_dict = match_scenes(frame_dict = frame_dict, pdf_file = pdf_file)
outfile = match_subs_to_pages(vtt_file = subs_file, page_dict = page_dict, save_target= out_file)
# Asks user if they want to delete the frames
delete_frames = input("Do you want to delete the created files? (Y/n): ")
if delete_frames.lower() == "n":
print(f"Frames saved to {working_dir}. Delete them manually before running the script again.")
else:
shutil.rmtree(working_dir)
print(f"Output saved to {outfile}")
print("Done")
if __name__ == "__main__":
main()