Add continuity check: abort if clip audio doesn't actually overlap

Distinguishes a genuine audio mismatch at a clip boundary (evidence
the inputs aren't really a continuous sequence) from a boundary that's
simply too quiet to judge either way, using an RMS floor alongside the
existing cross-correlation confidence score. A confident mismatch now
aborts before encoding instead of silently splicing unrelated clips
together; --allow-discontinuous opts back into the old behavior.
This commit is contained in:
2026-07-26 12:49:18 -04:00
parent 302afee062
commit ac3bdbcfe9
2 changed files with 66 additions and 15 deletions
+21 -1
View File
@@ -21,7 +21,11 @@ This script:
needed here).
2. Cross-correlates the audio at each clip boundary to measure the *actual*
overlap duration from the content itself (not just filename order or
whole-second creation timestamps, which aren't precise enough).
whole-second creation timestamps, which aren't precise enough). If a
boundary's audio simply doesn't match — a sign the inputs aren't actually
a continuous sequence (wrong order, a missing clip, unrelated files) — the
run aborts before encoding anything, rather than silently splicing
together clips that don't belong together.
3. Trims the duplicated span off the start of each subsequent clip.
4. Re-encodes the video across the joins (trimming mid-GOP HEVC can't be done
with a plain stream copy) and concatenates everything into one file.
@@ -75,6 +79,22 @@ python .\concat_live_clips.py (2441..2445 | ForEach-Object { "IMG_$_.MOV" })
| `--preset` | x265 preset (default: `medium`) |
| `--metadata-from N` | Take container metadata from the Nth input clip, 0-indexed (default: `0`, the first clip) |
| `--confidence-threshold N` | Minimum audio cross-correlation confidence required to trust an overlap detection before falling back to 0 (default: `0.9`) |
| `--min-signal-rms N` | Below this audio RMS level (int16 scale), a boundary is considered too quiet to judge continuity, so a low-confidence match there won't trigger an abort (default: `25`) |
| `--allow-discontinuous` | Proceed even if audio at a clip boundary doesn't match, instead of aborting |
`--crf`, `--bitrate`, and `--lossless` are mutually exclusive; the default
(no flag) auto-computes a bitrate target from the source clips.
### Continuity check
Before encoding, each clip boundary's audio is checked for a real match.
Three outcomes:
- **Confident match** (confidence ≥ `--confidence-threshold`) — the overlap
is measured and trimmed as normal.
- **Too quiet to tell** (signal below `--min-signal-rms`) — treated as 0
overlap and the run proceeds, since there's no reliable signal either way.
- **Confident mismatch** (enough signal, but it doesn't correlate) — treated
as evidence the clips aren't actually a continuous sequence, and the run
aborts with an error before any encoding happens. Pass
`--allow-discontinuous` to concatenate them anyway.