ffmpeg-skill 3.5.0 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/contract.md CHANGED
@@ -21,7 +21,7 @@ The contract is derived from the code that runs, not maintained beside it:
21
21
  | Field | Meaning | Changes when |
22
22
  |---|---|---|
23
23
  | `contract_version` | shape of this document (`2.0`) | a key is renamed, removed or changes meaning |
24
- | `skill.version` | the npm / package.json version (`3.5.0`) | any release |
24
+ | `skill.version` | the npm / package.json version (`3.6.0`) | any release |
25
25
 
26
26
  A release that adds a tool or a flag keeps `contract_version`; a breaking change to the
27
27
  ToolSpec shape bumps it. Consumers pin on `contract_version` and read `skill.version`
@@ -149,7 +149,7 @@ JSON would have been rewritten for that. The flat keys, typed per tool in `outpu
149
149
  "deprecated": [],
150
150
  "removed": [{"what": "...", "since": "1.10.0", "replacement": "...", "removed_in": "2.0.0", "where": "cli | json | mcp | behaviour"},
151
151
  {"what": "running on FFmpeg 5.x (the requirements.ffmpeg floor)", "since": "2.14.0", "replacement": "FFmpeg 6.1 or later; ...", "removed_in": "3.0.0", "where": "behaviour"}],
152
- "skill": {"id": "ffmpeg-skill", "version": "3.5.0", "execution_mode": "local", "kind": "execution",
152
+ "skill": {"id": "ffmpeg-skill", "version": "3.6.0", "execution_mode": "local", "kind": "execution",
153
153
  "entrypoints": {"cli": "...", "mcp": "...", "contract": "...", "doctor": "..."},
154
154
  "not_provided": ["AI reasoning", "decisions", "production plans", "project IR", "approvals", "network access", "transcription engine"]},
155
155
  "requirements": {"python": ">=3.10 (standard library only)", "ffmpeg": ">=6.1", "ffprobe": ">=6.1"},
@@ -752,7 +752,8 @@ silence a tool reported as fine while another measurement disagreed):
752
752
  | `verification[]` step `duration` | `export.py` (a preset with a platform maximum, without `--allow-long`) | the written file's length against the maximum, measured as `check.py` measures it (the container's duration, `tolerance` 0). A length that cannot be read fails the step with `reason: not_measured` |
753
753
  | `verification[]` step `duration` (`property: audio_duration`) | `loudness.py` | the output's sound against the input's, to one AAC frame (at least 0.03 s): a levels pass changes no timing. A length that cannot be read fails the step with `reason: not_measured` |
754
754
  | `inputs_duration`, `transition_shortening`; step `duration`'s `inputs_total` | `join.py` | the clips' own total and how much the transitions took out of it. `expected_duration` is derived from the transition the join applied, so it cannot show that on its own |
755
- | `margins` | `silence.py` | `{lead, tail}`: the seconds of each silence kept before speech starts (`--margin-lead`) and after it ends (`--margin-tail`); both equal `--margin` unless one is named. Absent under `--filler` without `--speech-aware`, which removes no silences |
755
+ | `margins` | `silence.py` | `{lead, tail}`: the seconds of each silence kept before speech starts (`--margin-lead`) and after it ends (`--margin-tail`); both equal `--margin` unless one is named. Absent under `--filler` with neither `--speech-aware` nor a sentence flag, which removes no silences |
756
+ | `silence_positions`, `sentence` | `silence.py --sentence-min-silence` / `--sentence-margin-tail` | per entry of `silences`, `sentence_end` when the transcript word before it ends in sentence-final punctuation, else `inside`; and `{min_silence, margin_tail, source, word_timings, sentence_end_words, silences}`. `sentence_end_words: 0` means the transcript had no such punctuation, so every silence used `--min-silence` and `--margin-tail` (warning `sentence_ends_not_found`) |
756
757
  | `silence_kinds`, `silence_breakdown` | `silence.py` | per detected silence, `digital` (at or below -90 dBFS) or `below_threshold` (quiet sound under `--threshold`), and the count and seconds of each with the level that defines it |
757
758
 
758
759
  Keys added after 2.21, all additive (#367 follow-up, and a report of a filename with a space that
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ffmpeg-skill",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "mcpName": "io.github.kajisho5/ffmpeg-skill",
5
5
  "description": "Agent Skill that gives coding agents (Claude Code, Cursor, Codex) a local video editor: 42 FFmpeg tools with a machine-readable contract, contract-derived MCP server, FFmpeg capability detection, probe-first / verify-last workflow. Cut, join, silence removal, fit, captions and karaoke, overlays, motion graphics, HDR to SDR, LUTs, audio clean-up and typed dynamics, sync with drift correction, multicam, loudness, delivery checks, project rendering, batch. No API keys, no cloud, no dependencies.",
6
6
  "keywords": [
@@ -697,7 +697,8 @@ each shorter clip's last frame (with silence) out to the longest.
697
697
 
698
698
  ### silence.py — remove dead air / jump cuts
699
699
  ```
700
- silence.py INPUT [--threshold -35] [--min-silence 0.6] [--margin 0.2] [--margin-lead S] [--margin-tail S] [--min-keep 0.2] [--list] [--edl keep.txt] [--timemap map.json|map.csv] [--speech-aware] [-o OUT]
700
+ silence.py INPUT [--threshold -35] [--min-silence 0.6] [--margin 0.2] [--margin-lead S] [--margin-tail S] [--min-keep 0.2] [--list]
701
+ [--sentence-min-silence S] [--sentence-margin-tail S] (with --words FILE or --transcribe) [--edl keep.txt] [--timemap map.json|map.csv] [--speech-aware] [-o OUT]
701
702
  silence.py INPUT --filler --words transcript.json [--filler-lang auto|en|ja|ko|zh|es|de|fr|pt|it|nl|pl|ru|tr]
702
703
  [--filler-words FILE] [--filler-extra W,W] [--filler-keep W,W] [--filler-pad 0.02]
703
704
  [--transcribe] [--engine auto|parakeet-mlx|parakeet.cpp|whisper.cpp|faster-whisper|openai-whisper]
@@ -721,6 +722,23 @@ is mostly breath wants more tail than the next word wants lead (`--margin-lead 0
721
722
  breaths inside a sentence and cuts only at sentence-boundary pauses. A `--threshold` set too high
722
723
  (-25, say) counts a weak word ending as silence: the result then warns.
723
724
 
725
+ **Pauses inside a sentence and after one.** With word timings (`--words FILE` or `--transcribe`),
726
+ `--sentence-min-silence S` and `--sentence-margin-tail S` give a silence that follows a sentence
727
+ end its own floor and its own tail; every other silence keeps `--min-silence` and `--margin-tail`.
728
+ A sentence end is a transcript word whose text ends in `. ! ? 。 ! ? …` (also `।` and `؟`), read
729
+ from the transcript and never from the sound; the word before a silence is the last one
730
+ whose own midpoint lies before the silence's midpoint, which holds when the engine stretched a
731
+ word's timing into the pause. `--words talk.json --min-silence 0.2 --sentence-min-silence
732
+ 0.3 --margin 0.1 --sentence-margin-tail 0.3` tightens pauses inside a sentence from 0.2 s and
733
+ after one from 0.3 s, leaving the sentence end more room. The result lists `silence_positions`
734
+ (`sentence_end` or `inside`, one per entry of `silences`) and `sentence` (`min_silence`,
735
+ `margin_tail`, `source`, `word_timings`, `sentence_end_words`, `silences`). With no such punctuation
736
+ in the transcript no silence is a sentence end: every one uses `--min-silence` and `--margin-tail`,
737
+ and the run warns `sentence_ends_not_found`. Not with `--speech-aware`,
738
+ which takes a sentence boundary from the pause's length instead; without a transcript the flags
739
+ are refused. With `--filler` they turn silence removal on as well (`--filler` alone removes
740
+ only the words), reading the same transcript.
741
+
724
742
  **Cut levels (2.22).** Every run measures the RMS level 50 ms either side of each cut on the
725
743
  source (`cut_points`: `source_time`, `output_time`, `edge` out/in, `rms_dbfs` of the loudest
726
744
  channel, `null` for digital silence; the whole key is `null`, with a `cut_levels_unmeasured`
@@ -243,7 +243,7 @@ DRY_RUN_ANALYSIS = {
243
243
  "scenes": "scene and audio-peak measurement runs; --sheet and --edl are not written",
244
244
  "report": "probe, loudness and contact-sheet measurements run; the HTML is not written",
245
245
  "cropdetect": "the cropdetect filter runs over the sampled windows to measure bars; this tool never writes a file regardless of --dry-run",
246
- "silence": "silencedetect runs so the reported silences and keep ranges are real; the cut output is not written. --filler --transcribe also runs the speech engine (its word timings are what the filler spans are planned on), which may download a model on first use",
246
+ "silence": "silencedetect runs so the reported silences and keep ranges are real; the cut output is not written. --filler --transcribe also runs the speech engine (its word timings are what the filler spans are planned on), which may download a model on first use; so does --transcribe with --sentence-min-silence or --sentence-margin-tail",
247
247
  "loudness": "the loudnorm measurement pass runs so input_i and the planned pass-2 command are real; the normalised output is not written",
248
248
  "check": "read-only tool; the loudness measurement (or, when it is skipped, the audio row's volumedetect) and the --content decode run under --dry-run too, so every row is present",
249
249
  "stabilize": "vidstabdetect (pass 1, into a temp file) runs; the stabilised output (pass 2) is not written",
@@ -500,6 +500,7 @@ DIAGNOSTIC_CODES = {
500
500
  "sync_low_confidence": ("warnings", "sync.py / multicam.py: a source's offset has a correlation confidence below 0.1; {path, confidence}"),
501
501
  "cropdetect_windows_failed": ("warnings", "cropdetect.py: sampled windows ffmpeg could not decode (windows_failed); {failed, windows, starts}"),
502
502
  "filler_words_untimed": ("warnings", "silence.py --filler: listed words in the transcript with no usable timing were not removed (filler.matched_untimed); {count}"),
503
+ "sentence_ends_not_found": ("warnings", "silence.py --sentence-min-silence / --sentence-margin-tail: the transcript has no sentence-final punctuation, so every silence used --min-silence and --margin-tail (sentence.sentence_end_words is 0)"),
503
504
  "cut_near_sound": ("warnings", "silence.py: a cut point's level is within CUT_SOUND_MARGIN_DB of --threshold, so it may land in a breath or a word's weak tail (cut_warnings lists them)"),
504
505
  "cut_levels_unmeasured": ("warnings", "silence.py: the source could not be decoded to measure the level at each cut; cut_points and cut_warnings are null (unmeasured, not silent)"),
505
506
  "filler_removal_caution": ("warnings", "silence.py --filler: a removed word that is often an ordinary word, or a discourse marker added with --filler-extra (also in filler.warnings)"),
@@ -652,7 +653,9 @@ def output_schema(name: str, meta: Dict[str, Any], hw: bool = False) -> Dict[str
652
653
  "beat_grid": {"type": "object", "description": "--beats (1.17): {supported_beats, tempo_bpm, interval, confidence, phase, onsets, supported, unsupported, method, step_s (the envelope's real step: 220/22050 s for --beat-step 0.01, after 3.2.0), range_bpm, usable, onset_refinement (after 3.2.0: pcm-window-ratio when each onset was placed on the decoded samples, else null)}"}}
653
654
  elif name == "silence":
654
655
  extra = {"silences": {"type": "array"}, "keep": {"type": "array"}, "input_duration": {"type": "number"}, "kept_duration": {"type": "number"}, "removed_seconds": {"type": "number"},
655
- "margins": {"type": "object", "description": "{lead, tail}: the seconds of each silence kept before speech starts (--margin-lead) and after it ends (--margin-tail); both are --margin unless one is named; absent under --filler without --speech-aware, which removes no silences"},
656
+ "margins": {"type": "object", "description": "{lead, tail}: the seconds of each silence kept before speech starts (--margin-lead) and after it ends (--margin-tail); both are --margin unless one is named; absent under --filler with neither --speech-aware nor a sentence flag, which removes no silences"},
657
+ "silence_positions": {"type": "array", "description": "--sentence-min-silence / --sentence-margin-tail: per entry of silences, sentence_end when the transcript word before it ends in sentence-final punctuation, else inside"},
658
+ "sentence": {"type": "object", "description": "--sentence-min-silence / --sentence-margin-tail: {min_silence, margin_tail (the floor and tail given to a silence after a sentence end), source, word_timings, sentence_end_words (transcript words that end a sentence; 0 means none did, so every silence used --min-silence and --margin-tail), silences (how many of silences are sentence_end)}"},
656
659
  "removed_seconds_total": {"type": "number", "description": "--filler: seconds removed in all, silence plus filler words (removed_seconds stays the silence alone)"},
657
660
  "cut_points": {"type": ["array", "null"], "description": "2.22: per cut {source_time, output_time, edge (out|in), rms_dbfs (the loudest channel 50 ms either side on the source; null for digital silence), filler (true on a removed filler word's edge)}; null when the source could not be decoded for it (cut_levels_unmeasured warning)"},
658
661
  "cut_warnings": {"type": ["array", "null"], "description": "the cut_points (not filler cuts) within 10 dB of --threshold: where to listen (a cut_near_sound warning); verified is unchanged"},
@@ -10,6 +10,8 @@ Examples:
10
10
  python3 silence.py talk.mp4 # -35 dB, gaps >= 0.6 s, 0.2 s margin
11
11
  python3 silence.py talk.mp4 --threshold -40 --min-silence 1 --margin 0.25
12
12
  python3 silence.py talk.mp4 --margin-lead 0.1 --margin-tail 0.4 # less before a word, more after one
13
+ python3 silence.py talk.mp4 --words talk.json --min-silence 0.2 --sentence-min-silence 0.3 --sentence-margin-tail 0.3
14
+ # pauses inside a sentence from 0.2 s, after one from 0.3 s with a longer tail
13
15
  python3 silence.py talk.mp4 --list # print the silences and the resulting cut list, no output
14
16
  python3 silence.py talk.mp4 --edl keep.txt # also save the kept ranges (START-END per line, cut.py --segments format)
15
17
  """
@@ -59,6 +61,76 @@ CUT_LEVEL_RATE = 8000
59
61
  CUT_LEVEL_CHANNELS = 2 # measured one by one; a surround source is folded to two first
60
62
  DIGITAL_SILENCE_DB = -90.0 # 2.20: at or below this a span is digital silence (16-bit dither sits near -96)
61
63
  BREATH_FLOOR = 0.12 # shortest gap silencedetect is asked for under --speech-aware
64
+ # a transcript word that ends in one of these (after any closing quote or bracket) ends a sentence
65
+ SENTENCE_END = ".!?\u3002\uff01\uff1f\u2026\u0964\u061f"
66
+ SENTENCE_CLOSERS = "\"'\u201d\u2019\u300d\u300f\uff09)]\u3011 "
67
+
68
+
69
+ def ends_sentence(word: str) -> bool:
70
+ """Whether a transcript word carries sentence-final punctuation: read off the text the speech
71
+ engine wrote, never guessed from the sound."""
72
+ text = str(word or "").rstrip(SENTENCE_CLOSERS)
73
+ return bool(text) and text[-1] in SENTENCE_END
74
+
75
+
76
+ def silence_positions(silences: List[Tuple[float, float]], words: "list",
77
+ duration: Optional[float] = None) -> List[str]:
78
+ """Per silence, `sentence_end` when the word spoken before it ends a sentence, else `inside`.
79
+ The word before a silence is the last one whose own midpoint lies before the silence's
80
+ midpoint; a silence that runs to the end of the file ends at `duration`. An engine
81
+ stretches a word's timing into the pause beside it, the end of the word before or the start
82
+ of the word after (on demos/footage/ai_talk_en.mp4 three word starts sit 0.45 to 0.5 s before
83
+ the sound does), and a word's midpoint stays on its own side of the pause either way. A
84
+ silence with no word before it is `inside`."""
85
+ timed = sorted(words, key=lambda w: w["start"] + w["end"])
86
+ out: List[str] = []
87
+ for s, e in silences:
88
+ if e == float("inf"):
89
+ e = max(s, duration) if duration is not None else s
90
+ ref = (s + e) / 2
91
+ before = [w for w in timed if (w["start"] + w["end"]) / 2 < ref]
92
+ out.append("sentence_end" if before and ends_sentence(before[-1]["word"]) else "inside")
93
+ return out
94
+
95
+
96
+ def sentence_words(args) -> "Tuple[list, str]":
97
+ """(word timings, where they came from) for --sentence-min-silence / --sentence-margin-tail.
98
+ Under --filler the transcript that run read or made is reused; otherwise --words is read, or
99
+ --transcribe runs the local engine. Refuses without one: where a sentence ends is taken from
100
+ the transcript's punctuation, and there is no reading it off a pause."""
101
+ def usable(words: "list", source: str) -> "Tuple[list, str]":
102
+ # a word with no length or a time that is not a number cannot be placed against a pause
103
+ timed = [w for w in words if math.isfinite(w["start"]) and math.isfinite(w["end"]) and w["end"] > w["start"]]
104
+ if not timed:
105
+ die(f"no usable word timings in the transcript ({source}): every word's start and end must be "
106
+ "numbers with the end after the start, or there is nothing to place a sentence end against a pause",
107
+ kind="input")
108
+ return timed, source
109
+
110
+ if getattr(args, "_words", None) is not None:
111
+ return usable(args._words, args._words_source)
112
+ if args.words:
113
+ try:
114
+ raw = json.loads(read_text_or_die(args.words, "--words"))
115
+ except ValueError as exc:
116
+ die(f"--words {args.words}: not readable JSON ({exc})", kind="input")
117
+ words, _had_segments, _untimed = _words_from_transcript(raw)
118
+ if not words:
119
+ die(f"no word timings in {args.words}: the sentence flags need "
120
+ '{"words": [{"word": ..., "start": ..., "end": ...}]} (or the same inside "segments").',
121
+ kind="input")
122
+ return usable(words, f"whisper-json:{args.words}")
123
+ if args.transcribe:
124
+ asr_run = _asr.transcribe_words_result(args.input, None, model=args.model, engine=args.engine)
125
+ args._asr_notes = list(asr_run.notes)
126
+ if not asr_run.words:
127
+ die(f"{asr_run.engine or 'the local engine'} ran but produced no word-level timings, so there is "
128
+ "nothing to tell a sentence end from. Pass a transcript with word timings as --words.", kind="input")
129
+ family = "parakeet" if asr_run.engine in _asr.PARAKEET_ENGINES else "whisper"
130
+ return usable(asr_run.words, f"{family}:{asr_run.engine}" if asr_run.engine else "whisper")
131
+ die("--sentence-min-silence and --sentence-margin-tail need word timings: pass --words transcript.json "
132
+ "(a whisper JSON with word timestamps) or --transcribe. A sentence end is read from the transcript's "
133
+ "punctuation; a pause's length does not say where one is.", kind="input")
62
134
 
63
135
 
64
136
  def speech_aware_silences(path: str, threshold: float, min_silence: float) -> "Tuple[List[Tuple[float, float]], List[Tuple[float, float]]]":
@@ -312,6 +384,7 @@ def resolve_filler(args, meta):
312
384
  "faster-whisper word_timestamps=True / openai-whisper --word_timestamps True) and "
313
385
  "pass the result with --words.", kind="input")
314
386
 
387
+ args._words, args._words_source = words, source # the sentence flags read the same transcript
315
388
  lang = args.filler_lang
316
389
  reported_lang = lang
317
390
  if lang == "auto":
@@ -466,6 +539,13 @@ def main() -> int:
466
539
  help="seconds of silence to keep after speech ends, when it should differ from --margin "
467
540
  "(default: --margin); a speaker whose last syllable trails off needs more here than "
468
541
  "before the next word")
542
+ ap.add_argument("--sentence-min-silence", type=float, default=None, metavar="SECONDS",
543
+ help="for a silence after a word that ends a sentence, remove it only when it is at least this "
544
+ "long, instead of --min-silence. Needs --words or --transcribe: a sentence end is the "
545
+ "transcript's punctuation")
546
+ ap.add_argument("--sentence-margin-tail", type=float, default=None, metavar="SECONDS",
547
+ help="for a silence after a word that ends a sentence, keep this much after the speech instead "
548
+ "of --margin-tail. Needs --words or --transcribe")
469
549
  ap.add_argument("--min-keep", type=float, default=0.2, help="drop kept pieces shorter than this (default 0.2)")
470
550
  ap.add_argument("--speech-aware", action="store_true",
471
551
  help="keep breaths shorter than --min-silence when they sit inside a sentence "
@@ -496,7 +576,7 @@ def main() -> int:
496
576
  fil.add_argument("--filler-pad", type=float, default=FILLER_PAD,
497
577
  help=f"seconds trimmed either side of a filler word (default {FILLER_PAD})")
498
578
  fil.add_argument("--words", metavar="FILE",
499
- help="a whisper JSON with word-level timings, for --filler")
579
+ help="a whisper JSON with word-level timings, for --filler and the sentence flags")
500
580
  fil.add_argument("--transcribe", action="store_true",
501
581
  help="produce the word timings with a local speech engine, Parakeet or whisper (never required; the same "
502
582
  "bridge caption.py uses)")
@@ -543,6 +623,19 @@ def main() -> int:
543
623
  # unless one is named
544
624
  tail = args.margin if args.margin_tail is None else args.margin_tail
545
625
  lead = args.margin if args.margin_lead is None else args.margin_lead
626
+ by_sentence = args.sentence_min_silence is not None or args.sentence_margin_tail is not None
627
+ for flag, value in (("--sentence-min-silence", args.sentence_min_silence),
628
+ ("--sentence-margin-tail", args.sentence_margin_tail)):
629
+ if value is not None and (not math.isfinite(value) or value < 0):
630
+ die(f"{flag} must be a finite number of seconds, 0 or more (got {value:g})", kind="input")
631
+ if by_sentence and args.speech_aware:
632
+ die("--speech-aware and the sentence flags answer the same question two ways: --speech-aware takes a "
633
+ "pause of --min-silence or longer as a sentence boundary, --sentence-min-silence and "
634
+ "--sentence-margin-tail take the transcript's punctuation. Pass one of them.", kind="input")
635
+ if by_sentence and not (args.words or args.transcribe):
636
+ sentence_words(args) # refuses: no transcript to read a sentence end from
637
+ sentence_min = args.min_silence if args.sentence_min_silence is None else args.sentence_min_silence
638
+ sentence_tail = tail if args.sentence_margin_tail is None else args.sentence_margin_tail
546
639
  if args.filler_pad < 0:
547
640
  die("--filler-pad cannot be negative: a negative pad turns each word's span inside out "
548
641
  "(end before start) and the span is then silently dropped, so nothing is removed",
@@ -558,16 +651,44 @@ def main() -> int:
558
651
  breaths: List[Tuple[float, float]] = []
559
652
  if args.speech_aware:
560
653
  silences, breaths = speech_aware_silences(args.input, args.threshold, args.min_silence)
561
- elif args.filler:
654
+ elif args.filler and not by_sentence:
562
655
  silences = [] # --filler alone: remove only the filler-word spans, not generic dead air
563
656
  else:
564
- silences = detect(args.input, args.threshold, args.min_silence)
657
+ # with the sentence flags each kind of pause has its own floor: measure at the shorter one
658
+ silences = detect(args.input, args.threshold, min(args.min_silence, sentence_min) if by_sentence else args.min_silence)
565
659
  filler_info, filler_ranges = resolve_filler(args, meta) if args.filler else (None, [])
660
+ positions: List[str] = []
661
+ sentence_info: Optional[Dict[str, Any]] = None
662
+ if by_sentence:
663
+ words, words_source = sentence_words(args)
664
+ found = silence_positions(silences, words, duration)
665
+ # a silence that runs to the end of the file is as long as what is left of the file
666
+ kept_pairs = [(span, pos) for span, pos in zip(silences, found)
667
+ if (duration if span[1] == float("inf") else span[1]) - span[0]
668
+ >= (sentence_min if pos == "sentence_end" else args.min_silence)]
669
+ silences = [span for span, _ in kept_pairs]
670
+ positions = [pos for _, pos in kept_pairs]
671
+ marked = sum(1 for w in words if ends_sentence(w["word"]))
672
+ sentence_info = {"min_silence": sentence_min, "margin_tail": sentence_tail, "source": words_source,
673
+ "word_timings": len(words), "sentence_end_words": marked,
674
+ "silences": positions.count("sentence_end")}
675
+ if not marked:
676
+ warn("the transcript has no sentence-final punctuation, so no silence was taken as a sentence end: "
677
+ "every silence used --min-silence and --margin-tail", "sentence_ends_not_found")
678
+
679
+ def margined(spans: List[Tuple[float, float]]) -> List[Tuple[float, float]]:
680
+ """The stretch of each silence that is removed: its own tail for one after a sentence end."""
681
+ if not by_sentence:
682
+ return inside_margin(spans, duration, tail, lead)
683
+ out: List[Tuple[float, float]] = []
684
+ for span, pos in zip(spans, positions):
685
+ out += inside_margin([span], duration, sentence_tail if pos == "sentence_end" else tail, lead)
686
+ return out
566
687
  # One sorted, merged removal list through the graph the tool already has: filler removal IS
567
688
  # time-range removal, so it reuses keep_ranges() and the same select chain.
568
689
  # --margin is kept around the silences only (inside_margin), not around filler spans, whose
569
690
  # own trim is --filler-pad (#414); the merged list then goes through with no further margin.
570
- removals = merge_spans(inside_margin(silences, duration, tail, lead) + list(filler_ranges))
691
+ removals = merge_spans(margined(silences) + list(filler_ranges))
571
692
  keeps = keep_ranges(removals, duration, 0.0, args.min_keep)
572
693
  # what the render holds (on a picture, each bound on its nearest frame): the report, the EDL
573
694
  # and the time map all describe these, so a re-cut or a sum of `keep` is the rendered edit
@@ -582,7 +703,7 @@ def main() -> int:
582
703
  # the silences alone; everything removed is `removed_seconds_total`.
583
704
  silence_only = removed
584
705
  if args.filler:
585
- silence_keeps = keep_ranges(merge_spans(inside_margin(silences, duration, tail, lead)), duration, 0.0, args.min_keep)
706
+ silence_keeps = keep_ranges(merge_spans(margined(silences)), duration, 0.0, args.min_keep)
586
707
  silence_only = max(0.0, duration - sum(e - s for s, e in rendered_ranges(silence_keeps, meta, duration, video_out)))
587
708
  kinds = silence_kinds(args.input, silences, duration, args.threshold)
588
709
  summary = {
@@ -592,11 +713,15 @@ def main() -> int:
592
713
  "kept_duration": round(kept, 3),
593
714
  "removed_seconds": round(silence_only, 3),
594
715
  }
595
- if silences or not args.filler or args.speech_aware:
716
+ if silences or not args.filler or args.speech_aware or by_sentence:
596
717
  # the seconds of each silence this run kept: `tail` from where the silence starts (after
597
718
  # the speech before it), `lead` up to where it ends (before the speech after it). Absent
598
- # under --filler alone, which detects no silences and so applies neither.
719
+ # under --filler with neither --speech-aware nor a sentence flag: no silence is detected.
599
720
  summary["margins"] = {"lead": lead, "tail": tail}
721
+ if sentence_info is not None:
722
+ # which of `silences` follow a sentence end, and the floor and tail those were given
723
+ summary["silence_positions"] = positions
724
+ summary["sentence"] = sentence_info
600
725
  if kinds:
601
726
  summary.update(kinds)
602
727
  if args.speech_aware:
@@ -628,7 +753,7 @@ def main() -> int:
628
753
  die(f"{len(keeps)} keep ranges is above --max-cuts {args.max_cuts}: the filter graph grows "
629
754
  "with every range and a graph this size is slow and fragile. Raise --max-cuts if you "
630
755
  "mean it, or use --min-silence/--filler-pad to merge the short ones.", kind="input")
631
- filler_only = args.filler and not args.speech_aware
756
+ filler_only = args.filler and not args.speech_aware and not by_sentence
632
757
  if filler_only:
633
758
  info(f"--filler only (no --speech-aware): skipping generic silence detection, "
634
759
  f"keeping {len(keeps)} range(s): {kept:.2f}s of {duration:.2f}s (removing {removed:.2f}s, filler only)")