Adding some files

This commit is contained in:
2026-05-11 21:45:30 +02:00
parent b9376cd650
commit feb4df0506
3 changed files with 142 additions and 43 deletions
+39 -11
View File
@@ -234,7 +234,7 @@ Examples:
args.res,
)
elif action == "trim":
return cmd_trim(project_path, args.verbose, args.force, args.threshold)
return cmd_trim(project_path, args.verbose, args.force, args.threshold, args.res)
elif action == "transcode":
return cmd_transcode(
project_path,
@@ -1197,7 +1197,7 @@ def cmd_preprocess(
"""
from concurrent.futures import ThreadPoolExecutor, as_completed
from .parser import parse_project_config, parse_videos
from .preprocessor import preprocess_video
from .preprocessor import preprocess_video, RES_CONFIGS
from .models import VideoSource as _VideoSource
mode_str = f" ({res.upper()})" if res != "full" else ""
@@ -1278,7 +1278,15 @@ def cmd_preprocess(
if using_compressed and segment_id.endswith("_compressed"):
segment_id = segment_id[: -len("_compressed")]
output_file = f"processed/{segment_id}_processed.mov"
# For non-full res, write into the res subdir so stitch --res low finds the
# files at narration/low/processed/ (narration.json still records the plain
# "processed/..." path; stitch shifts the base dir itself).
_res_cfg = RES_CONFIGS.get(res) if res != "full" else None
if _res_cfg:
_, _, _subdir = _res_cfg
output_file = f"{_subdir}/processed/{segment_id}_processed.mov"
else:
output_file = f"processed/{segment_id}_processed.mov"
output_path = narration_dir / output_file
if output_path.exists() and not force:
@@ -1343,6 +1351,7 @@ def cmd_preprocess(
verbose=False,
force=force,
custom_gnommo_scratch=gnommo_scratch,
res=res,
)
return task
@@ -1371,6 +1380,7 @@ def cmd_preprocess(
verbose,
force,
gnommo_scratch,
res=res,
)
output_path = narration_dir / segment_source.output_file
if output_path.exists():
@@ -1396,8 +1406,8 @@ def cmd_preprocess(
for key in _PRESERVE_KEYS:
if key in existing_entry:
entry[key] = existing_entry[key]
# Point source_file to the processed output
entry["source_file"] = segment_source.output_file
# Always record the plain path; stitch shifts the base dir for low/tiny.
entry["source_file"] = f"processed/{segment_id}_processed.mov"
entry.setdefault("use_audio_channels", "auto")
entry.setdefault("defer_loudnorm", True)
existing_narration[segment_id] = entry
@@ -1437,7 +1447,7 @@ def cmd_preprocess(
continue
print(f" Processing: {video_id}")
preprocess_video(
videos_dir, video_id, video_source, verbose, force, gnommo_scratch
videos_dir, video_id, video_source, verbose, force, gnommo_scratch, res=res
)
print("\nPreprocessing complete.")
@@ -1454,6 +1464,7 @@ def cmd_trim(
verbose: bool,
force: bool = False,
threshold_db: float = -40.0,
res: str = "full",
) -> int:
"""
Auto-detect silence bounds for all narration segments and write skip/take
@@ -1482,6 +1493,22 @@ def cmd_trim(
print(" Run 'gnommo -p <project> import' first.")
return 1
# Build a lookup of raw source files by segment ID. Raw files give cleaner
# silence detection — loudnorm can introduce early peaks in processed audio.
_video_exts = {".mov", ".mp4", ".avi", ".mkv", ".m4v"}
raw_dir = narration_dir / "raw_mov"
compressed_dir = narration_dir / "raw_mp4"
raw_lookup: dict[str, Path] = {}
for search_dir in (raw_dir, compressed_dir):
if search_dir.exists():
for f in search_dir.iterdir():
if f.is_file() and f.suffix.lower() in _video_exts and not f.name.startswith("."):
stem = f.stem
if stem.endswith("_compressed"):
stem = stem[: -len("_compressed")]
raw_lookup[stem] = f
narration_json_path = narration_dir / "narration.json"
raw_data: dict = _read_json(narration_json_path)
@@ -1495,14 +1522,15 @@ def cmd_trim(
print(f" {seg_id}: already trimmed, skipping (use --force to redo)")
continue
# Always analyse the raw source file — it's always present and has the
# same audio as any processed version (processing is video-only).
source_path = narration_dir / seg.source_file
# Prefer raw file; fall back to processed if raw not available.
source_path = raw_lookup.get(seg_id)
if source_path is None:
source_path = narration_dir / seg.source_file
if not source_path.exists():
print(f" {seg_id}: source file not found ({seg.source_file}), skipping")
print(f" {seg_id}: source file not found, skipping")
continue
print(f" {seg_id}: analysing...", end="", flush=True)
print(f" {seg_id}: analysing {source_path.parent.name}/{source_path.name}...", end="", flush=True)
first_sound, last_sound = detect_silence_bounds(
source_path, noise_threshold_db=threshold_db, verbose=verbose
)