ffmpeg-skill 3.8.8 → 3.8.9

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/README.md CHANGED
@@ -400,7 +400,7 @@ The short list for humans. The agent-facing version, with the reasoning, is the
400
400
  - **Filler words (1.17).** `silence.py --filler --words transcript.json` removes "um" and "uh" through the same cut graph the silences use. Never without measured word timings — there is no heuristic that finds an "um" without them that would not also cut real speech — and `like`, `tipo` and `cioè` are deliberately not in the built-in lists, because a discourse marker is a content word. Built-in lists since 2.19: English, Japanese, Korean, Chinese, Spanish, German, French, Portuguese, Italian, Dutch, Polish, Russian and Turkish; any other language takes `--filler-words FILE`. Whisper stays optional: `--transcribe` with no engine installed refuses and names the five installs.
401
401
  - **Throughput (1.17).** `batch.py --jobs N` runs several files at once, capped at `min(N, cpu_count, 8)` and sharing one `--timeout` budget rather than one per item; the per-item table keeps its order. `render.py --cache DIR` reuses stages whose inputs and arguments did not change, so swapping an export preset re-runs export only. The cache is opt-in with no default directory, and the ffmpeg, skill and contract versions are part of every key, so a cache is never reused across them.
402
402
  - **Audiogram (1.16).** `waveform.py --image cover.png` (or `render.py --template audiogram`) puts the waveform over a still plate for an episode that has no picture, with `--platform` for the frame, `--title` and burnt-in captions. The image is a local file you give: nothing is fetched and no cover art is ever invented.
403
- - **Emoji in captions and titles (1.15).** `caption.py`/`graphics.py --emoji-assets DIR` composites a PNG per emoji (Twemoji/Noto naming, `1f389.png`) on top of the text, because drawtext cannot load a colour emoji font at all and an installed one does not prove libass will draw it in colour — `doctor --json`'s `fonts.emoji` answers that from a render probe. Without assets the run still succeeds and reports `mode: mono`. Nothing is ever downloaded.
403
+ - **Emoji in captions and titles (1.15).** `caption.py`/`graphics.py --emoji-assets DIR` composites a PNG per emoji (Twemoji naming, `1f389.png`, or Noto's `emoji_u1f389.png`) on top of the text, because drawtext cannot load a colour emoji font at all and an installed one does not prove libass will draw it in colour — `doctor --json`'s `fonts.emoji` answers that from a render probe. Without assets the result's `emoji.mode` says which of three things happened: `color` when this build's libass draws the colour glyph (also for `--emoji mono` on such a build, with a warning), `mono` when it draws a monochrome one, and `none` when nothing here draws the glyph, in which case the emoji are left out of the text with an `emoji_not_drawn` warning (and a `graphics.py` title that is nothing but emoji is refused). Nothing is ever downloaded.
404
404
  - **Indic and Thai text shaped correctly in titles and lower-thirds (1.15).** `graphics.py` renders Devanagari, Bengali, Tamil, Thai and Lao through libass automatically (`text_renderer: "ass"`), because drawtext never reorders matras or re-clusters marks; Arabic and Hebrew were already correct on a fribidi build. `--text-render drawtext` with such a script is refused, never rendered wrongly.
405
405
  - **Non-Latin text picks a font by script (1.12).** Japanese, Chinese, Korean, Arabic, Hebrew, Devanagari, Thai, Cyrillic and Greek cues, titles and overlays resolve a font file that covers them automatically, and a machine with no such font fails the job (`kind: input`) instead of rendering boxes. `doctor --json`'s `fonts.scripts` says which languages this machine can render; `--lang ja|ko` disambiguates Han-only text, and `--lang zh-TW` (or `zh-HK`, `zh-Hant`) picks a Traditional Chinese face (2.19); an explicit `--font`/`--font-file` is always kept.
406
406
  - **Silence detection finds nothing?** The default threshold is −35 dBFS. The tool prints a hint with the track's measured level; raise the threshold (`silence.py --threshold -25`) or shorten `--min-silence`.
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.8.8`) | any release |
24
+ | `skill.version` | the npm / package.json version (`3.8.9`) | 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.8.8", "execution_mode": "local", "kind": "execution",
152
+ "skill": {"id": "ffmpeg-skill", "version": "3.8.9", "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"},
@@ -878,7 +878,17 @@ An ffmpeg run that fails keeps `kind: ffmpeg` and exit code 1, and since 3.1.0 c
878
878
  (`_common.runner.FFMPEG_FAILURE_CLASSES`): `disk_full` ("No space left on device"),
879
879
  `encoder_missing` and `filter_missing` (`details.name`; the build lacks it, `doctor` says how to
880
880
  get one that has it), `input_incomplete` ("moov atom not found": a cut-off recording or an
881
- unfinished copy, which `--repair` cannot rebuild) and `input_unreadable`. A tool that copies the
881
+ unfinished copy, which `--repair` cannot rebuild) and `input_unreadable`. After 3.8.4 an ffmpeg
882
+ command a tool runs through `run()` that names an encoder (`-c:v`/`-c:a`/`-c:s` and their
883
+ spellings, after the last input, for a stream kind the output keeps: not one `-an`/`-vn`/`-sn`
884
+ drops or no input file carries) or a filter (`-vf`, `-af`, `-filter:v`, `-filter:a`,
885
+ `-filter_complex`, `-lavfi`) the build's own list lacks is refused with that same `kind`, `reason`
886
+ and `details.name` before ffmpeg runs, under `--dry-run` too
887
+ (`_common.runner._check_build_components()`). Not checked: a measurement pass run through
888
+ `run_analysis()` (`loudness.measure()` and its loudnorm filter, for one: a pass that reports its
889
+ own failure carries ffmpeg's `reason` after the run, `ffmpeg_failure_extra()`), a VideoToolbox encoder,
890
+ a `-filter_complex_script` or lavfi input, an explicit `-map` selection, and any command when the
891
+ list could not be read (that refuses nothing). A tool that copies the
882
892
  source's subtitle and data streams retried the whole encode without them after any failure; it
883
893
  now retries only when the source has such a stream and the failure is none of these.
884
894
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ffmpeg-skill",
3
- "version": "3.8.8",
3
+ "version": "3.8.9",
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": [
@@ -271,9 +271,11 @@ directory of PNGs — and on most builds only the second one exists.
271
271
  to 48 pixels: invalid library handle`, and at the font's own strike
272
272
  `Monocromatic (1bpp) fonts are not supported.`) and no file is written. That
273
273
  is why the colour route is a PNG overlay, never a drawtext font.
274
- - **PNGs**: `--emoji-assets DIR`, a directory of files named by code point in
275
- the Twemoji/Noto convention — lowercase hex joined by `-`: `1f389.png`,
276
- `1f1ef-1f1f5.png`, `1f469-200d-1f4bb.png`. Twemoji's `assets/72x72`
274
+ - **PNGs**: `--emoji-assets DIR`, a directory of files named by code point:
275
+ Twemoji's lowercase hex joined by `-` (`1f389.png`, `1f1ef-1f1f5.png`,
276
+ `1f469-200d-1f4bb.png`), or Noto Emoji's `emoji_u` names, each code point at
277
+ least four hex digits, joined by `_` (`emoji_u1f389.png`,
278
+ `emoji_u0031_20e3.png`). Twemoji's `assets/72x72`
277
279
  (CC-BY 4.0) and Noto Emoji's `png/128` (OFL/Apache-2.0) are the two people
278
280
  already have. **The skill never downloads anything**: a missing directory is
279
281
  `kind: input`, never a silent fetch. The same directory can come from
@@ -353,7 +353,9 @@ the stored size, because the filter measures the picture after ffmpeg applies
353
353
  the tag. Distinct from
354
354
  `fit.py --fit crop`, which crops to a target aspect ratio it computes
355
355
  itself with no black-bar measurement involved. A rectangle that matches the
356
- full source frame means no bars were found. Does not decide whether
356
+ full source frame means no bars were found: a picture that reaches every edge
357
+ is reported as the frame itself, and `--round` (default 16) rounds a detected
358
+ crop only (1080 is not a multiple of 16). Does not decide whether
357
359
  removing detected bars is wanted -- genuine letterboxed content (a
358
360
  scope-ratio film in a 16:9 frame) "detects" the same way as accidental
359
361
  bars; look at the frame before cropping it away. `windows` / `windows_failed`
@@ -653,7 +655,8 @@ metadata.py INPUT [--chapters chapters.txt | --clear-chapters | --auto-chapters]
653
655
  [--title T] [--artist A] [--album A] [--comment C] [--date D] [--genre G] [-o OUT]
654
656
  ```
655
657
  `chapters.txt` holds one chapter per line, `TIME TITLE` (cut.py's time syntax:
656
- seconds, mm:ss, hh:mm:ss.ms); each chapter ends where the next starts and the
658
+ seconds, mm:ss, hh:mm:ss.ms; a `-`, dash, `|` or `:` between the two, as in
659
+ `0:00 - Intro`, is not part of the title); each chapter ends where the next starts and the
657
660
  last runs to the end of the file. Starts must ascend and lie inside the file.
658
661
  Every stream is `-c copy` (bit for bit; `probe` reports the result under
659
662
  `chapters` and `tags`), so this is instant and lossless. Chapter markers need a
@@ -766,7 +769,7 @@ leaves none. A dry run writes nothing.
766
769
  **`--filler` (1.17)** removes filler words as well, through the same
767
770
  `keep_ranges()` graph with more, shorter ranges. It is **never**
768
771
  applied without measured word timings: pass `--words` (a whisper JSON carrying
769
- per-word `start`/`end`) or `--transcribe` (the same local engine `caption.py`
772
+ per-word `start`/`end`, or whisper.cpp's `--output-json-full` document) or `--transcribe` (the same local engine `caption.py`
770
773
  uses, never required). There is no heuristic fallback — finding an "um" by
771
774
  looking for short quiet blips would cut real speech, so the tool refuses
772
775
  instead. `--filler-list` reports what would go and writes nothing.
@@ -871,7 +874,9 @@ packet count must equal the clips' total and its video length their summed lengt
871
874
  `copy`. `--copy` does not take `--width`, `--height`, `--fps`, `--sample-rate`, `--channels` or a transition, and an
872
875
  audio-only join (which resamples every clip to one format) is refused with it.
873
876
  `--list FILE` (2.2) reads the clips from a file, one per line in order, paths relative to the
874
- file (blank lines and `#` comments ignored; ffmpeg's `file 'x.wav'` lines accepted), for the
877
+ file (blank lines and `#` comments ignored; ffmpeg's `file 'x.wav'` lines and the `ffconcat version` header accepted,
878
+ any other concat directive -- `inpoint`, `outpoint`, `duration`, the argument-free `stream` -- refused, since join.py
879
+ applies none, unless the line names a file that is there), for the
875
880
  segments a TTS or render step wrote. Every input -- listed or given as arguments -- is checked
876
881
  before anything runs: missing, empty (0 bytes) or unreadable as media. By default all of them
877
882
  are named in one refusal (`kind: input`, `problems: [{index, path, reason}]`, nothing encoded);
@@ -1795,8 +1800,8 @@ stays text (escaped), and under `--karaoke` `<font color>` is dropped for the hi
1795
1800
  colours. The ASS is kept next to the
1796
1801
  user can hand-tune timings and re-run with `--ass`.
1797
1802
  Emoji (1.15): `--emoji-assets DIR` is a directory of PNGs named by code point
1798
- (`1f389.png`, `1f1ef-1f1f5.png`, `1f469-200d-1f4bb.png` — the Twemoji/Noto
1799
- convention), also read from `brand.json` `styles.caption.emoji_assets` and
1803
+ (`1f389.png`, `1f1ef-1f1f5.png`, `1f469-200d-1f4bb.png` — the Twemoji
1804
+ convention; Noto Emoji's `emoji_u1f389.png`, `emoji_u0031_20e3.png` are found too), also read from `brand.json` `styles.caption.emoji_assets` and
1800
1805
  `FFMPEG_SKILL_EMOJI_ASSETS`. With one, the cue text keeps its place in the ASS
1801
1806
  with an invisible placeholder reserving the emoji's box and each PNG is
1802
1807
  composited on top (`--emoji-scale` sizes the box, `--emoji-max` caps the count).
@@ -128,11 +128,22 @@ def srt_timing_times(line: str) -> Tuple[str, str]:
128
128
  return a.strip(), words[0] if words else ""
129
129
 
130
130
 
131
+ # WebVTT's inline word timestamps and its class, voice and language spans (YouTube's automatic
132
+ # captions: `hello<00:00:01.500><c> world</c>`); <i>, <b> and <u> are SRT's too and stay
133
+ _VTT_INLINE = re.compile(r"<\d{1,2}:\d{2}(?::\d{2})?\.\d{3}>|</?(?:c|v|lang)(?:[.\s][^>]*)?>")
134
+
135
+
131
136
  def parse_srt(path: str) -> List[Tuple[float, float, str]]:
132
137
  cues: List[Tuple[float, float, str]] = []
133
- for times, body in srt_blocks(read_text_or_die(path, "--srt")):
138
+ source = read_text_or_die(path, "--srt")
139
+ # only in a file that says it is WebVTT: ffmpeg's own WebVTT reader drops these tags, and the
140
+ # cues this function returns were burned with them in the text (#404)
141
+ vtt = source.lstrip().upper().startswith("WEBVTT")
142
+ for times, body in srt_blocks(source):
134
143
  a, b = srt_timing_times(times)
135
144
  text = "\n".join(body).strip()
145
+ if vtt:
146
+ text = _VTT_INLINE.sub("", text).strip()
136
147
  try:
137
148
  cues.append((parse_time(a), parse_time(b), text))
138
149
  except ValueError as e: # includes MissingFpsError: SRT timings are hh:mm:ss,ms, never frames
@@ -121,6 +121,17 @@ def drawtext_shaping() -> "Dict[str, bool]":
121
121
  return dict(_SHAPING_BUILD_CACHE)
122
122
 
123
123
 
124
+ def shaping_refusal(script: str) -> str:
125
+ """Why drawtext cannot draw `script` here, as the clause after "<Language> text": on any build
126
+ for the scripts harfbuzz reorders, on this build for Arabic and Hebrew, which a build with
127
+ fribidi draws (#402: both were refused as "on any ffmpeg build")."""
128
+ if script in BIDI_SCRIPTS:
129
+ return ("cannot be shaped by drawtext on this ffmpeg build (it was built without libfribidi, which "
130
+ "drawtext needs for right-to-left order and Arabic joining; a build with it draws this text)")
131
+ return ("cannot be shaped by drawtext on any ffmpeg build (the marks are reordered by harfbuzz, which "
132
+ "drawtext does not use)")
133
+
134
+
124
135
  def needs_shaping(script: str) -> bool:
125
136
  """Whether drawtext would render `script` wrongly on this build."""
126
137
  if script in SHAPING_SCRIPTS:
@@ -778,8 +778,10 @@ def decode_step(path: str, meta: Dict[str, Any], kinds: Sequence[str], window: f
778
778
  # (bounded, so a failing hour-long stream is not decoded whole)
779
779
  frames[kind]["tail"] = tail_frames(max(0.0, end - origin - window - DECODE_LONG_GOP_SECONDS))
780
780
  bad = [k for k in kinds if not all(frames[k].values())]
781
+ # no provenance: it says where an expected value came from, and this step has none (#403: it
782
+ # said "measurement", which is not one of the contract's values)
781
783
  step: Dict[str, Any] = {"step": "decode", "property": "decodable", "frames": frames, "window": window,
782
- "provenance": "measurement", "ok": not bad}
784
+ "ok": not bad}
783
785
  if bad:
784
786
  step["undecodable"] = [k for k in bad if k not in unmeasured]
785
787
  if unmeasured:
@@ -187,7 +187,7 @@ def has_emoji(text: str) -> bool:
187
187
 
188
188
  def emoji_codepoint_name(cluster: str) -> str:
189
189
  """The asset filename stem for a cluster: lowercase hex code points joined by '-', the
190
- Twemoji/Noto convention (1f389, 1f469-200d-1f4bb, 1f1ef-1f1f5)."""
190
+ Twemoji convention (1f389, 1f469-200d-1f4bb, 1f1ef-1f1f5); emoji_asset_for() also tries Noto's."""
191
191
  return "-".join(f"{ord(c):x}" for c in cluster)
192
192
 
193
193
 
@@ -214,13 +214,36 @@ def emoji_asset_for(cluster: str, assets_dir: "Optional[str]") -> "Optional[str]
214
214
  if not assets_dir or not os.path.isdir(assets_dir):
215
215
  return None
216
216
  for name in _emoji_name_candidates(cluster):
217
- for ext in (".png", ".PNG"):
218
- candidate = os.path.join(assets_dir, name + ext)
219
- if os.path.isfile(candidate):
220
- return candidate
217
+ # Twemoji's name (1f469-200d-1f4bb.png, 31-20e3.png), then Noto Emoji's, whose code points
218
+ # are at least four hex digits (emoji_u1f469_200d_1f4bb.png, emoji_u0031_20e3.png): the hint
219
+ # names noto-emoji/png/128, whose files were never found (#404)
220
+ for stem in (name, "emoji_u" + "_".join(cp.zfill(4) for cp in name.split("-"))):
221
+ for ext in (".png", ".PNG"):
222
+ candidate = os.path.join(assets_dir, stem + ext)
223
+ if os.path.isfile(candidate):
224
+ return candidate
221
225
  return None
222
226
 
223
227
 
228
+ def emoji_mono_on_colour_note(support: "Dict[str, Any]") -> str:
229
+ """--emoji mono on a build whose libass draws the emoji face in colour: nothing here makes that
230
+ glyph monochrome (mono and color build the same text), so the result says color (#403: the
231
+ warning said "no colour path" beside a detail saying it renders in colour)."""
232
+ return ("--emoji mono: libass draws the emoji face in colour on this build and nothing here makes it "
233
+ "monochrome, so the emoji are drawn in colour (mode: color). " + str(support.get("detail") or ""))
234
+
235
+
236
+ def emoji_missing_asset_note(missing: "List[str]", support: "Dict[str, Any]") -> str:
237
+ """What happens to the clusters --emoji-assets has no PNG for: they stay in the text for libass,
238
+ which is said as measured (libass_glyph), not as "drawn by the text font" (#403)."""
239
+ names = ", ".join(missing)
240
+ if support.get("libass_glyph") is False:
241
+ return (f"no PNG in the assets directory for {names} -- those clusters stay in the text, and libass draws no "
242
+ "emoji glyph on this build: an empty box at best")
243
+ return (f"no PNG in the assets directory for {names} -- those clusters stay in the text for libass to draw "
244
+ "with an installed face" + ("" if support.get("libass_glyph") else " (whether one has the glyph was not measured)"))
245
+
246
+
224
247
  EMOJI_ASSET_HINT = (
225
248
  "point --emoji-assets at a directory of PNGs named by code point (1f389.png): "
226
249
  "twemoji/assets/72x72 (Twemoji, CC-BY 4.0) or noto-emoji/png/128 (Noto Emoji, OFL/Apache-2.0) "
@@ -13,7 +13,7 @@ import statistics
13
13
  from fractions import Fraction
14
14
  from typing import Any, Dict, List, Optional, Sequence, Tuple
15
15
  from _common.emit import die, warn
16
- from _common.runner import STATE, dry_run_input_pending, require_tool, run, run_analysis, still_input_args
16
+ from _common.runner import ffmpeg_failure_extra, STATE, dry_run_input_pending, require_tool, run, run_analysis, still_input_args
17
17
 
18
18
  # The streams probe() describes, as stream specifiers: its `video` is the first picture that is not
19
19
  # a cover (`V`), its `audio` the first sound stream. Without a -map, FFmpeg picks the largest
@@ -63,7 +63,7 @@ def decode_pcm_mono(path: str, sample_rate: int, seconds: Optional[float] = None
63
63
  proc = run_analysis(cmd, check=False, text=False)
64
64
  if proc.returncode != 0 or not proc.stdout:
65
65
  if check:
66
- die(f"could not decode audio from {path}:\n{proc.stderr.decode(errors='replace').strip()}", kind="ffmpeg")
66
+ die(f"could not decode audio from {path}:\n{proc.stderr.decode(errors='replace').strip()}", kind="ffmpeg", **ffmpeg_failure_extra(proc.stderr.decode(errors="replace")))
67
67
  return []
68
68
  n = len(proc.stdout) // 2
69
69
  import struct
@@ -113,7 +113,7 @@ def decode_gray_frames(path: str, fps: float, width: int, height: int, *, start:
113
113
  proc = run_analysis(cmd, check=False, text=False)
114
114
  if proc.returncode != 0 or not proc.stdout:
115
115
  if check:
116
- die(f"could not decode frames from {path}:\n{proc.stderr.decode(errors='replace').strip()}", kind="ffmpeg")
116
+ die(f"could not decode frames from {path}:\n{proc.stderr.decode(errors='replace').strip()}", kind="ffmpeg", **ffmpeg_failure_extra(proc.stderr.decode(errors="replace")))
117
117
  return []
118
118
  frame_size = width * height
119
119
  data = proc.stdout
@@ -208,10 +208,12 @@ def probe(path: str, role: str = "input") -> Dict[str, Any]:
208
208
 
209
209
  role="output" marks a file this tool just wrote: a read failure is then reported as an
210
210
  output-verification failure (kind "output") instead of an input problem."""
211
- if not os.path.exists(path):
211
+ if not os.path.exists(path) or (role == "output" and STATE.dry_run):
212
212
  if role == "output" and not STATE.dry_run:
213
213
  _output_failed(path, "not written")
214
214
  if STATE.dry_run:
215
+ # also for an output path that holds a file: a dry run did not write it, and reading it
216
+ # reported an earlier run's file as this plan's result (#403: cut.py's output_duration)
215
217
  # width/height/fps are honestly 0/0/0.0 -- "not measured", matching duration/size_bytes
216
218
  # below -- because this is a dry run: the file doesn't exist yet, so there is nothing to
217
219
  # probe. Earlier this stub used plausible-looking placeholders (1920x1080x30.0) instead,
@@ -840,6 +842,24 @@ def measure_signal_range(path: str, standard: str, window: float = 10.0,
840
842
  return doc
841
843
 
842
844
 
845
+ def refuse_not_a_still(path: str, meta: Dict[str, Any], flag: str, instead: str) -> None:
846
+ """`flag` takes a still image and is read with `-loop 1`, an option of the image demuxers only:
847
+ a video or a GIF (one frame or many: the gif demuxer has no such option) given there failed as
848
+ "Option loop not found" / "Option framerate not found", naming neither the file nor the flag
849
+ (#404). `instead` says what takes a video."""
850
+ fmt = str(meta.get("format") or "")
851
+ if STATE.dry_run and meta.get("dry_run"):
852
+ return # a pending input: nothing was read
853
+ if fmt == "image2" or fmt.endswith("_pipe"):
854
+ return
855
+ if fmt == "gif":
856
+ die(f"{flag} {path} is a GIF, and {flag} reads a still image through the image demuxers, which do not "
857
+ "open GIF: convert it to PNG first (`look.py FILE --at 0 -o still.png` writes its first frame)", kind="input")
858
+ length = meta.get("duration")
859
+ die(f"{flag} {path} is not a still image: it is a {fmt.split(',')[0] or 'media'} file"
860
+ + (f" ({length:.3f}s)" if length else "") + f", and {flag} is read as one picture", kind="input", hint=instead)
861
+
862
+
843
863
  def analyze_levels(path: str, seconds: float = 20.0) -> Dict[str, Any]:
844
864
  """Sample luma/saturation statistics (signalstats) and guess whether the picture is Log-encoded.
845
865
 
@@ -1023,7 +1043,7 @@ def detect_silences(path: str, threshold: float, min_silence: float) -> "List[Tu
1023
1043
  f"silencedetect=noise={threshold}dB:d={min_silence}", "-f", "null", "-"]
1024
1044
  proc = run_analysis(cmd, check=False, record=True)
1025
1045
  if proc.returncode != 0:
1026
- die(f"silencedetect failed:\n{proc.stderr.strip()[-800:]}", kind="ffmpeg")
1046
+ die(f"silencedetect failed:\n{proc.stderr.strip()[-800:]}", kind="ffmpeg", **ffmpeg_failure_extra(proc.stderr))
1027
1047
  silences: "List[Tuple[float, float]]" = []
1028
1048
  start = None
1029
1049
  for kind, val in SIL_RE.findall(proc.stderr):
@@ -1085,7 +1105,7 @@ def detect_content(path: str, duration: float, *, video: bool = True, audio: boo
1085
1105
  cmd += ["-map", "0:a:0", "-af", f"silencedetect=noise={SILENT_PEAK_DBFS:g}dB:d={CONTENT_SILENCE_MIN}"]
1086
1106
  proc = run_analysis(cmd + ["-f", "null", "-"], check=False, record=True)
1087
1107
  if proc.returncode != 0:
1088
- die(f"content detection failed:\n{proc.stderr.strip()[-800:]}", kind="ffmpeg")
1108
+ die(f"content detection failed:\n{proc.stderr.strip()[-800:]}", kind="ffmpeg", **ffmpeg_failure_extra(proc.stderr))
1089
1109
  end = max(duration, 0.0)
1090
1110
  out: Dict[str, Any] = {}
1091
1111
  if video:
@@ -1129,7 +1149,7 @@ def _detect_dropouts(path: str, end: float) -> "List[Tuple[float, float]]":
1129
1149
  f"silencedetect=noise={CONTENT_DROPOUT_DB:g}dB:d={CONTENT_DROPOUT_MIN}", "-f", "null", "-"],
1130
1150
  check=False, record=True)
1131
1151
  if proc.returncode != 0:
1132
- die(f"dropout detection failed:\n{proc.stderr.strip()[-800:]}", kind="ffmpeg")
1152
+ die(f"dropout detection failed:\n{proc.stderr.strip()[-800:]}", kind="ffmpeg", **ffmpeg_failure_extra(proc.stderr))
1133
1153
  gaps: "List[Tuple[float, float]]" = []
1134
1154
  start = None
1135
1155
  for kind, val in SIL_RE.findall(proc.stderr):
@@ -1048,7 +1048,7 @@ _CODEC_OPTION_RE = re.compile(r"^-(?:c|codec)(?::([va])(?::\d+)?)?$|^-(v|a)codec
1048
1048
 
1049
1049
 
1050
1050
  def _an_input_has(cmd: Sequence[str], kind: str) -> bool:
1051
- """False only when every input of `cmd` is a file that was read and holds no `kind` ("v"/"a")
1051
+ """False only when every input of `cmd` is a file that was read and holds no `kind` ("v"/"a"/"s")
1052
1052
  stream, and no filter graph could make one. An encoder option for a stream the output will
1053
1053
  not have selects nothing (FFmpeg applies -c:a after stream selection), so it is not a reason
1054
1054
  to refuse: cut.py names -c:a aac for a silent source too. Anything not known counts as present."""
@@ -1110,6 +1110,120 @@ def _check_container_codecs(cmd: Sequence[str]) -> None:
1110
1110
  output=output, container="webm", encoders=refused)
1111
1111
 
1112
1112
 
1113
+ # the options whose value is a filter graph this module can read the filter names out of
1114
+ _GRAPH_OPTIONS = frozenset({"-vf", "-af", "-filter:v", "-filter:a", "-filter_complex", "-lavfi"})
1115
+ _ENCODER_OPTION_RE = re.compile(r"^-(?:c|codec):([vas])(?::\d+)?$|^-([vas])codec$")
1116
+ # the output option that drops every stream of a kind: an encoder named for that kind selects nothing
1117
+ _NO_STREAM_OPTION = {"v": "-vn", "a": "-an", "s": "-sn"}
1118
+ # one row of `ffmpeg -encoders` / `ffmpeg -filters` (the filter row by its io-spec token, so the
1119
+ # flag-column width of FFmpeg 6/7 and 8+ does not matter): ffmpeg_encoders(), ffmpeg_filters()
1120
+ _ENCODER_ROW = r"^\s*[VAS][.\w]{5}\s+(\S+)"
1121
+ _FILTER_ROW = r"^\s*(?:[A-Z.|]{1,6}\s+)?([A-Za-z0-9_]+)\s+\S*->\S*"
1122
+ # quiet reads of a list the tool itself never asked for: {"-encoders": names, "-filters": names}
1123
+ _PREFLIGHT_LISTS: Dict[str, set] = {}
1124
+
1125
+
1126
+ def graph_filter_names(graph: str) -> List[str]:
1127
+ """The filter names of one filter graph string, in order, without duplicates. A `,` or `;`
1128
+ separates filters only outside '...' quotes and when no backslash escapes it; `[labels]` before
1129
+ a filter and its `=options` / `@instance` are dropped. A graph-level `sws_flags=` is not a
1130
+ filter and is left out, as is anything that is not a plain identifier."""
1131
+ parts: List[str] = []
1132
+ cur: List[str] = []
1133
+ quoted = False
1134
+ i = 0
1135
+ while i < len(graph):
1136
+ ch = graph[i]
1137
+ if ch == "\\" and i + 1 < len(graph):
1138
+ cur.append(graph[i:i + 2])
1139
+ i += 2
1140
+ continue
1141
+ if ch == "'":
1142
+ quoted = not quoted
1143
+ elif ch in ",;" and not quoted:
1144
+ parts.append("".join(cur))
1145
+ cur = []
1146
+ i += 1
1147
+ continue
1148
+ cur.append(ch)
1149
+ i += 1
1150
+ parts.append("".join(cur))
1151
+ names: List[str] = []
1152
+ for part in parts:
1153
+ part = part.strip()
1154
+ while part.startswith("["):
1155
+ end = part.find("]")
1156
+ if end < 0:
1157
+ break
1158
+ part = part[end + 1:].lstrip()
1159
+ m = re.match(r"[A-Za-z0-9_]+", part)
1160
+ if not m or m.end() < len(part) and part[m.end()] not in "=@[ \t":
1161
+ continue
1162
+ if m.group(0) != "sws_flags" and m.group(0) not in names:
1163
+ names.append(m.group(0))
1164
+ return names
1165
+
1166
+
1167
+ def _build_list(flag: str) -> set:
1168
+ """This build's encoder or filter names for the check below: the list a tool already read, else
1169
+ one quiet read. A list that cannot be read is empty here and refuses nothing; the
1170
+ `ffmpeg_list_unreadable` warning stays with the tools that decide something on the list."""
1171
+ cached = _ENCODERS if flag == "-encoders" else _FILTERS
1172
+ if cached is not None:
1173
+ return cached
1174
+ if flag not in _PREFLIGHT_LISTS:
1175
+ _PREFLIGHT_LISTS[flag] = _read_ff_list(flag, _ENCODER_ROW if flag == "-encoders" else _FILTER_ROW, quiet=True)
1176
+ return _PREFLIGHT_LISTS[flag]
1177
+
1178
+
1179
+ def _check_build_components(cmd: Sequence[str]) -> None:
1180
+ """An encoder or a filter the command names and this ffmpeg build does not have is refused
1181
+ before anything runs, dry runs included, with the kind, reason and hint the run got from
1182
+ ffmpeg's "Unknown encoder" / "No such filter" (#402): the dry run said completed, and a real
1183
+ run found out after its earlier commands had run. Read from the command as built, so every tool
1184
+ and every route to an encoder (an HDR source kept as HEVC, --codec, a preset) is covered.
1185
+ Only output options are read (a -c:v before an -i picks a decoder), and an encoder only for a
1186
+ stream kind the output keeps: not one -an/-vn/-sn drops or no input file carries. A VideoToolbox encoder is
1187
+ left to --hw's own checks and its CPU retry, a -filter_complex_script and a lavfi input are not
1188
+ parsed, and a list that could not be read refuses nothing."""
1189
+ last_input = max((i for i, tok in enumerate(cmd[:-1]) if tok == "-i"), default=-1)
1190
+ encoders: List[str] = []
1191
+ streams: Dict[str, set] = {} # encoder -> the stream kinds ("v", "a", "s") it is named for
1192
+ filters: List[str] = []
1193
+ output_opts = {str(tok) for tok in cmd[last_input + 2:-1]}
1194
+ for i in range(1, len(cmd) - 1):
1195
+ tok, value = str(cmd[i]), str(cmd[i + 1])
1196
+ m = _ENCODER_OPTION_RE.match(tok)
1197
+ if tok in _GRAPH_OPTIONS:
1198
+ filters += [n for n in graph_filter_names(value) if n not in filters]
1199
+ elif i > last_input and m and value != "copy" and not value.endswith("_videotoolbox"):
1200
+ if value not in encoders:
1201
+ encoders.append(value)
1202
+ streams.setdefault(value, set()).add(m.group(1) or m.group(2))
1203
+
1204
+ def selected(name: str) -> bool:
1205
+ # ffmpeg picks an encoder per output stream, after stream selection: one named for a kind
1206
+ # the output drops (-an/-vn/-sn) or that no input carries (cut.py names -c:a aac for a
1207
+ # silent source too) is never opened. What the command cannot tell (a -filter_complex graph, a
1208
+ # lavfi or unreadable input) counts as selected; explicit -map lists are not read.
1209
+ return any(_NO_STREAM_OPTION[k] not in output_opts and _an_input_has(cmd, k) for k in streams.get(name, ()))
1210
+
1211
+ for flag, wanted, what, reason in (("-encoders", encoders, "encoder", "encoder_missing"),
1212
+ ("-filters", filters, "filter", "filter_missing")):
1213
+ have = _build_list(flag) if wanted else set()
1214
+ missing = [n for n in wanted if n not in have] if have else []
1215
+ if what == "encoder":
1216
+ missing = [n for n in missing if selected(n)] # asked last: only an encoder that would be refused is probed for
1217
+ if missing:
1218
+ name = missing[0]
1219
+ hint = filter_missing_hint(name) if what == "filter" else filter_missing_hint(name).replace(
1220
+ f"no {name} filter", f"no {name} encoder", 1)
1221
+ die(f"this ffmpeg build has no {name} {what}, which the command this run builds needs"
1222
+ + (f" (also missing: {', '.join(missing[1:])})" if missing[1:] else ""),
1223
+ code=1, kind="ffmpeg", hint=hint,
1224
+ error_extra={"reason": reason, "details": {"name": name}})
1225
+
1226
+
1113
1227
  EVEN_SCALE = "scale=trunc(iw/2)*2:trunc(ih/2)*2"
1114
1228
 
1115
1229
 
@@ -1904,6 +2018,7 @@ def run(cmd: Sequence[str], *, quiet: bool = False, check: bool = True, ctx: "Op
1904
2018
  _check_no_overwrite_input(cmd)
1905
2019
  _check_output_path(cmd)
1906
2020
  _check_container_codecs(cmd)
2021
+ _check_build_components(cmd)
1907
2022
  _check_existing_output(cmd)
1908
2023
  ctx.commands.append(_cmdline(cmd))
1909
2024
  if not quiet:
@@ -2128,6 +2243,16 @@ def _has_non_av_streams(cmd: Sequence[str]) -> bool:
2128
2243
  return not kinds or bool(kinds & {"subtitle", "data", "attachment"})
2129
2244
 
2130
2245
 
2246
+ def ffmpeg_failure_extra(stderr: str) -> Dict[str, Any]:
2247
+ """The die() keywords that carry the cause ffmpeg named in `stderr` -- a missing encoder or
2248
+ filter, a full disk, an unreadable input -- as `hint` and the error's `reason`/`details`, or {}
2249
+ when it named none (#402): a tool that composes its own failure message (cut.py's re-encode, a
2250
+ measurement pass) reports the cause as run()'s own failures do. Used as
2251
+ `die(msg, kind="ffmpeg", **ffmpeg_failure_extra(proc.stderr))`, through the caller's own die."""
2252
+ cls = classify_ffmpeg_failure(stderr or "")
2253
+ return {"hint": cls[1], "error_extra": {"reason": cls[0], "details": cls[2]}} if cls else {}
2254
+
2255
+
2131
2256
  def fail_if_classified(proc: subprocess.CompletedProcess) -> None:
2132
2257
  """Stop with a failed attempt's own error when ffmpeg named a cause a second encode would hit
2133
2258
  the same way (a full disk, a missing encoder or filter, an unreadable input): the rule
@@ -2543,7 +2668,7 @@ def ffmpeg_encoders() -> set:
2543
2668
  refusal or a CPU note built on the empty set names the read failure, not a missing encoder."""
2544
2669
  global _ENCODERS
2545
2670
  if _ENCODERS is None:
2546
- _ENCODERS = _read_ff_list("-encoders", r"^\s*[VAS][.\w]{5}\s+(\S+)")
2671
+ _ENCODERS = _read_ff_list("-encoders", _ENCODER_ROW)
2547
2672
  return _ENCODERS
2548
2673
 
2549
2674
 
@@ -2565,7 +2690,7 @@ def ffmpeg_filters() -> set:
2565
2690
  flag-column width of FFmpeg 6/7 (three) and 8+ (two) does not matter."""
2566
2691
  global _FILTERS
2567
2692
  if _FILTERS is None:
2568
- _FILTERS = _read_ff_list("-filters", r"^\s*(?:[A-Z.|]{1,6}\s+)?([A-Za-z0-9_]+)\s+\S*->\S*")
2693
+ _FILTERS = _read_ff_list("-filters", _FILTER_ROW)
2569
2694
  return _FILTERS
2570
2695
 
2571
2696
 
@@ -2605,12 +2730,13 @@ def ffmpeg_list_error(flag: str) -> Optional[str]:
2605
2730
  return None if cache else _LIST_ERRORS.get(flag)
2606
2731
 
2607
2732
 
2608
- def _read_ff_list(flag: str, pattern: str) -> set:
2733
+ def _read_ff_list(flag: str, pattern: str, quiet: bool = False) -> set:
2609
2734
  tool = "ffprobe" if STATE.dry_run else "ffmpeg"
2610
2735
  # --timeout bounds this read too: on Apple Silicon every CPU re-encode asks for the list
2611
2736
  # (#314), so a deadlocked ffmpeg must not outlive the limit the caller set before the encode
2612
2737
  limit = _probe_limit()
2613
- _LIST_ERRORS.pop(flag, None)
2738
+ if not quiet:
2739
+ _LIST_ERRORS.pop(flag, None)
2614
2740
  names: set = set()
2615
2741
  why = None
2616
2742
  try:
@@ -2625,6 +2751,8 @@ def _read_ff_list(flag: str, pattern: str) -> set:
2625
2751
  why = f"{tool} {flag} did not answer within {limit:g} s"
2626
2752
  except (OSError, subprocess.SubprocessError) as exc:
2627
2753
  why = f"{tool} {flag} could not run: {exc}"
2754
+ if why and quiet:
2755
+ return set()
2628
2756
  if why:
2629
2757
  _LIST_ERRORS[flag] = why
2630
2758
  what = {"-encoders": "encoder", "-decoders": "decoder", "-bsfs": "bitstream filter"}.get(flag, "filter")