rereel cut-retakes
Analyzes a raw narration recording (audio or video) and returns a list of kept segments with source offsets and new timeline positions. The source file is never modified or re-encoded, and playback speed is never changed (tempoRatio is always 1.0). Paste the segments into mix_plan.json narration[] to apply the cut.
Synopsis
Section titled “Synopsis”rereel cut-retakes --input <audio_or_video> [--asr-json <path>] [--script <path>] [--out <json>] [--silence-db -40] [--min-silence-sec 0.45] [--keep-gap-sec 0.14] [--pad-edge-sec 0.05] [--fade-sec 0.015] [--target-sec <sec>]The input may also be given as the first positional argument (rereel cut-retakes raw.wav).
What it does
Section titled “What it does”- Fails with exit
2if the input does not exist orffprobecannot determine a positive duration. - Picks a detection mode:
Mode A: ASR-based (--asr-json given and the file exists)
Section titled “Mode A: ASR-based (--asr-json given and the file exists)”- Builds utterances from the Whisper-style JSON. Words come from
segments[].words[]. A segment without words contributes its wholetextas one word. A new utterance starts when the gap between a word’sstartand the current utterance’sendis>= --min-silence-sec, or when the current text ends with。!?!?.. Word strings are concatenated as-is. - Filler removal: an utterance whose normalized text (NFKC, lower-cased, punctuation and whitespace stripped) is empty or one of
あー えー えーと えっと あのー うーん まあ そのー um uh er erm ah likeis dropped with reasonfiller. - Retake removal, in one of two ways:
- Script-guided (
--scriptgiven and the file exists): the script is cleaned (front matter,#headings, and HTML comments removed) and split into sentences after。!?!?.or a newline. Sentences with fewer than 2 normalized characters are ignored. Each utterance is matched to the sentence with the highest score, where the score is the larger of the Dice bigram similarity and0.75when the utterance has ≥ 3 characters and the sentence starts with its first (up to 8) characters. A score>= 0.35counts as a match. When several utterances map to the same sentence, only the last one is kept, and earlier ones are dropped with reasonretake. Unmatched utterances are kept. - Transcript-free: an utterance is dropped as
retakewhen the next utterance starts with the same firstmin(len, nextLen, 6)characters (≥ 3) and is at least as long, or when the Dice similarity to the next utterance is>= 0.65.
- Script-guided (
--silence-db is not used in this mode.
Mode B: waveform silence (no usable --asr-json)
Section titled “Mode B: waveform silence (no usable --asr-json)”Runs ffmpeg -af silencedetect=noise=<silence-db>dB:d=<min-silence-sec>. Each detected silence is dropped with reason silence, and the audio between silences is kept if it is longer than 0.05 s.
Common post-processing
Section titled “Common post-processing”- Each kept range is widened by
--pad-edge-secon both sides (clamped to the source duration). Ranges shorter than 0.04 s are discarded. - Gap: segments are laid out back-to-back on a new timeline separated by
--keep-gap-sec. With--target-secand more than one segment, the gap becomes(target − totalSpeech) / (n − 1), clamped to[0.05, keepGap + sourceDuration × 0.15 / (n − 1)]. Speech is never stretched, so the target is approximate. - Each segment gets
fadeInSec = fadeOutSec = min(--fade-sec, duration / 4). - All times are rounded to 4 decimals. With
--out, the result is also written as pretty-printed JSON.
Options
Section titled “Options”| Flag | Type | Default | Description |
|---|---|---|---|
--input (or 1st positional) |
path | — (required) | Source audio/video. |
--asr-json |
path | — | Whisper JSON with word timestamps. Silently ignored if the file does not exist. |
--script |
path | — | Target script (Markdown or plain text) for script-guided retake removal. Used only together with --asr-json. Ignored if missing. |
--out |
path | — | Also write the result JSON to this file. Parent directories are created. |
--silence-db |
number (dB) | -40 |
silencedetect noise threshold (Mode B). |
--min-silence-sec |
number | 0.45 |
Minimum silence to cut (Mode B) / utterance split gap (Mode A). |
--keep-gap-sec |
number | 0.14 |
Pause inserted between kept segments. |
--pad-edge-sec |
number | 0.05 |
Padding added before/after each kept range. |
--fade-sec |
number | 0.015 |
Micro-fade at segment boundaries (capped at a quarter of the segment). |
--target-sec |
number | — | Approximate target duration; only the gaps are adjusted. 0 is treated as unset. |
The programmatic API additionally accepts maxStretchRatio (default 0.15). See cutRetakesAndSilence.
ASR JSON input
Section titled “ASR JSON input”{ "language": "en", "segments": [ { "start": 0.0, "end": 2.1, "text": " Today we will…", "words": [ { "word": " Today", "start": 0.0, "end": 0.32, "probability": 0.98 }, { "word": " we", "start": 0.34, "end": 0.45 } ] } ]}Output
Section titled “Output”Shape: CutRetakesResult.
{ "sourcePath": "./raw/narration_take1.wav", "sourceDurationSec": 61.237, "keptDurationSec": 44.982, "removedSec": 16.255, "tempoRatio": 1, "segments": [ { "id": "seg_001", "srcStartSec": 0.41, "srcEndSec": 3.92, "durationSec": 3.51, "timelineStartSec": 0, "timelineEndSec": 3.51, "fadeInSec": 0.015, "fadeOutSec": 0.015, "text": " Today we will look at rereel." } ], "dropped": [ { "srcStartSec": 4.1, "srcEndSec": 5.0, "reason": "retake", "text": " Today we wi" }, { "srcStartSec": 5.2, "srcEndSec": 5.6, "reason": "filler", "text": " um" } ], "speechIntervals": [[0, 3.51]]}Mapping to mix_plan.json
Section titled “Mapping to mix_plan.json”CutSegment |
narration[] field |
|---|---|
id |
id |
timelineStartSec |
start_sec |
srcStartSec |
src_start_sec |
durationSec |
duration_sec |
fadeInSec / fadeOutSec |
fade_in_sec / fade_out_sec |
text |
text |
speechIntervals can be copied to mix_plan.json speech to drive BGM ducking.
Exit codes
Section titled “Exit codes”| Code | When |
|---|---|
0 |
Success. |
2 |
No input, input not found, duration undetectable, non-numeric option, or invalid ASR JSON. |
3 |
ffmpeg/ffprobe not found. |
4 |
ffmpeg/ffprobe exited non-zero. |
Examples
Section titled “Examples”Script-guided retake removal fitted to roughly 45 s:
rereel cut-retakes \ --input ./raw/narration_take1.wav \ --asr-json ./raw/asr.json \ --script ./script.md \ --target-sec 45 \ --out ./reels/ep01/cuts.jsonPure silence trimming with a stricter threshold:
rereel cut-retakes --input ./raw/vo.wav --silence-db -35 --min-silence-sec 0.6