forked from LiveCarta/ContentGeneration
Add skip-audio mode and resilient merge handling
This commit is contained in:
@@ -6,10 +6,11 @@ from __future__ import annotations
|
||||
import argparse
|
||||
import logging
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from logging_config import configure_logging, debug_log_lifecycle
|
||||
from logging_config import configure_logging
|
||||
|
||||
|
||||
SCRIPT_DIR = Path(__file__).resolve().parent
|
||||
@@ -32,14 +33,14 @@ def parse_args() -> argparse.Namespace:
|
||||
parser.add_argument("--audios-dir", type=Path, default=DEFAULT_AUDIOS_DIR)
|
||||
parser.add_argument("--output-dir", type=Path, default=DEFAULT_OUTPUT_DIR)
|
||||
parser.add_argument(
|
||||
"--log-level",
|
||||
default=None,
|
||||
help="Logging level (overrides LOG_LEVEL env var)",
|
||||
"--allow-missing-audio",
|
||||
action="store_true",
|
||||
help="If set, create merged output from video only when audio is missing.",
|
||||
)
|
||||
parser.add_argument("--log-level", default="INFO")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@debug_log_lifecycle
|
||||
def main() -> int:
|
||||
args = parse_args()
|
||||
configure_logging(args.log_level)
|
||||
@@ -55,14 +56,24 @@ def main() -> int:
|
||||
audio = args.audios_dir / f"output_{num}.mp3"
|
||||
output = args.output_dir / f"merged_{num}.mp4"
|
||||
|
||||
if not audio.exists():
|
||||
LOGGER.warning("No audio found for shot %s (%s); skipped", num, audio)
|
||||
continue
|
||||
|
||||
if output.exists():
|
||||
LOGGER.info("Already exists; skipped shot %s", num)
|
||||
continue
|
||||
|
||||
if not audio.exists():
|
||||
if args.allow_missing_audio:
|
||||
LOGGER.warning(
|
||||
"No audio found for shot %s (%s); using video-only output",
|
||||
num,
|
||||
audio,
|
||||
)
|
||||
shutil.copy2(video, output)
|
||||
LOGGER.info("Done (video-only): %s", output)
|
||||
continue
|
||||
|
||||
LOGGER.warning("No audio found for shot %s (%s); skipped", num, audio)
|
||||
continue
|
||||
|
||||
LOGGER.info("Merging shot %s: %s + %s -> %s", num, video, audio, output)
|
||||
subprocess.run(
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user