-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_editor.py
More file actions
72 lines (60 loc) · 2.09 KB
/
Copy pathrun_editor.py
File metadata and controls
72 lines (60 loc) · 2.09 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""Build a video from scene images and narration audio."""
import argparse
import json
import os
from pipeline import config, editor
def _load_segments(path):
with open(path, "r", encoding="utf-8-sig") as handle:
return json.load(handle)
def main():
parser = argparse.ArgumentParser(
description="Stitch scene images into a video synced to narration audio."
)
parser.add_argument(
"--images",
default=config.IMAGE_DIR,
help=f"Folder containing scene images. Defaults to {config.IMAGE_DIR}.",
)
parser.add_argument(
"--audio",
default=config.FULL_AUDIO,
help="Narration audio path.",
)
parser.add_argument(
"--segments",
default=config.TRANSCRIPT_JSON,
help="Transcript JSON from run_pipeline.py.",
)
parser.add_argument(
"--output",
default=config.FINAL_VIDEO,
help="Path to the final mp4 output.",
)
parser.add_argument(
"--use-filename-timestamps",
action="store_true",
help="Use image filenames like 1-29.png as timeline anchors instead of transcript JSON.",
)
args = parser.parse_args()
if not os.path.exists(args.audio):
raise FileNotFoundError(f"Audio file not found: {args.audio}")
if not os.path.isdir(args.images):
raise NotADirectoryError(f"Image folder not found: {args.images}")
use_filename_timestamps = args.use_filename_timestamps or editor.images_have_filename_timestamps(args.images)
segments = None
if not use_filename_timestamps:
if not os.path.exists(args.segments):
raise FileNotFoundError(
f"Transcript JSON not found: {args.segments}. "
"Use run_pipeline.py first or pass --use-filename-timestamps."
)
segments = _load_segments(args.segments)
editor.stitch_images_to_video(
image_dir=args.images,
audio_path=args.audio,
output_path=args.output,
segments=segments,
use_filename_timestamps=use_filename_timestamps,
)
if __name__ == "__main__":
main()