Add segmented opt-in output: one segment-N/segment.txt per segment with @PictureN/@AudioN tokens
This commit is contained in:
parent
45b4c1c211
commit
738b2e30e8
10
README.md
10
README.md
@ -6,7 +6,8 @@ ready-to-run generation package:
|
||||
- `segments.txt` — N segment prompts, joined by `|`. The video creator node splits the
|
||||
total length evenly across segments (`N = max(1, round(total_seconds / 10))`) and
|
||||
generates them one by one. Default format is full-reference (ref2va); FL2VA
|
||||
(first–last frame) is an opt-in alternative.
|
||||
(first–last frame) and segmented (one `segment-N/segment.txt` file per segment with
|
||||
`@PictureN`/`@AudioN` tokens) are opt-in alternatives.
|
||||
- `Image-N.json` — one 16:9 character-sheet text-to-image prompt per character that
|
||||
has no user-provided image reference, consumed one at a time by a ComfyUI workflow.
|
||||
- `Segment-img-N.json` — one 16:9 first-frame image prompt per segment, rendered by
|
||||
@ -22,6 +23,7 @@ ready-to-run generation package:
|
||||
| `SKILL.md` | Skill entry point: triggers, mode selection, pipeline, output contract, validation checklist |
|
||||
| `references/ref2va-segment-format.md` | Authoritative per-segment format for the default mode (sections, labels, shots, audio template) |
|
||||
| `references/fl2va-segment-format.md` | The opt-in FL2VA first–last frame video prompt format |
|
||||
| `references/segmented-output-format.md` | The opt-in segmented layout: one `segment-N/segment.txt` per segment with `@PictureN`/`@AudioN` tokens, otherwise identical to ref2va |
|
||||
| `references/t2i-character-sheet.md` | Character-sheet caption rules (four-panel photorealistic turnaround) and the two-key JSON contract |
|
||||
| `references/frame-image-prompts.md` | Per-segment first/last frame image prompt rules (`Segment-img-N.json`) |
|
||||
| `references/worked-example.md` | Complete end-to-end example, including the audio (singing) and FL2VA variants |
|
||||
@ -34,10 +36,12 @@ ready-to-run generation package:
|
||||
2. Give the agent a vague scene prompt and the total video length in seconds, plus
|
||||
optionally: song lyrics, an audio file mention (e.g. "use midnight.mp3"),
|
||||
per-character image references, style hints, and — only if wanted — an explicit
|
||||
request for FL2VA / first-last frame mode.
|
||||
request for FL2VA / first-last frame mode or segmented one-file-per-segment
|
||||
output with `@PictureN`/`@AudioN` references.
|
||||
3. The agent writes `segments.txt`, `Image-N.json` for characters lacking references,
|
||||
`Segment-img-N.json` (and `Segment-img-N-last.json` in FL2VA mode), and
|
||||
`image-map.txt` into the project folder.
|
||||
4. Verify before use: `python3 scripts/validate_outputs.py --segments segments.txt
|
||||
--expected-n <N> [--dir .] [--lyrics-file lyrics.txt]` — add
|
||||
`--mode fl2va --total-seconds <seconds>` for FL2VA runs.
|
||||
`--mode fl2va --total-seconds <seconds>` for FL2VA runs, or
|
||||
`--mode segmented --segments-dir <folder>` for segmented runs.
|
||||
|
||||
36
SKILL.md
36
SKILL.md
@ -1,6 +1,6 @@
|
||||
---
|
||||
name: mm-prompter
|
||||
description: Writes multi-segment ref2va video prompts plus T2I character-sheet prompts and per-segment first-frame image prompts from a vague scene idea and a total video length in seconds. Use when the user gives a rough video/scene concept (optionally with song lyrics or an audio file name) and wants numbered video-generation segments joined by "|", character sheets as Image-N.json for characters that lack an image reference, Segment-img-N.json frame prompts, and an image-map.txt manifest. Optional opt-in FL2VA mode adds last-frame prompts and first-last video prompts.
|
||||
description: Writes multi-segment ref2va video prompts plus T2I character-sheet prompts and per-segment first-frame image prompts from a vague scene idea and a total video length in seconds. Use when the user gives a rough video/scene concept (optionally with song lyrics or an audio file name) and wants numbered video-generation segments joined by "|", character sheets as Image-N.json for characters that lack an image reference, Segment-img-N.json frame prompts, and an image-map.txt manifest. Optional opt-in FL2VA mode adds last-frame prompts and first-last video prompts. Optional opt-in segmented mode writes one segment-N/segment.txt file per segment using @PictureN/@Audio1-style @-references instead of the joined file.
|
||||
---
|
||||
|
||||
# MM Prompt Creator
|
||||
@ -10,8 +10,9 @@ generation package:
|
||||
|
||||
1. `segments.txt` — N segment prompts, joined by `|`. The downstream video creator
|
||||
node splits the total length evenly across segments and generates them one by one.
|
||||
Default format is full-reference (ref2va); FL2VA (first–last frame) is an opt-in
|
||||
alternative (see Mode selection).
|
||||
Default format is full-reference (ref2va); FL2VA (first–last frame) and segmented
|
||||
(one `segment-N/segment.txt` file per segment with `@PictureN`/`@AudioN` tokens)
|
||||
are opt-in alternatives (see Mode selection).
|
||||
2. `Image-N.json` — one 16:9 character-sheet text-to-image prompt per character that has
|
||||
no user-provided image reference. Consumed one at a time by a ComfyUI workflow.
|
||||
3. `Segment-img-N.json` — one 16:9 first-frame image prompt per segment (both modes);
|
||||
@ -36,6 +37,13 @@ example (including the audio and FL2VA variants) is in `references/worked-exampl
|
||||
character sheets. The sheets are still generated: they feed the image side, which
|
||||
renders the first/last frames with consistent characters. If the user's wording is
|
||||
ambiguous, stay in ref2va mode; never mix the two formats in one run.
|
||||
- **Segmented (opt-in).** Switch when the user asks for each segment as its own
|
||||
`segment.txt` file or for `@Picture1` / `@Audio1`-style references. This is an
|
||||
adaptation of ref2va defined in `references/segmented-output-format.md`: the
|
||||
segment content follows `references/ref2va-segment-format.md` unchanged, but each
|
||||
segment is written to its own `segment-N/segment.txt` file (no `segments.txt`, no
|
||||
`|` separators) and reference tokens are written as `@PictureN` / `@AudioN`;
|
||||
`<Subject N>` stays unchanged. Never mix formats in one run.
|
||||
|
||||
## Inputs
|
||||
|
||||
@ -119,14 +127,19 @@ User-supplied files keep their filenames; generated sheets are always `Image-N.j
|
||||
The manifest never lists frame files — `Segment-img-N` numbering follows segments,
|
||||
not subjects.
|
||||
|
||||
**Step 9 — Assemble `segments.txt`.** Strip each segment text, join with a single `|`
|
||||
(no spaces added around it). Exactly n segments, exactly n−1 `|` characters, no
|
||||
trailing separator, no extra headers or numbering. The `|` character must never appear
|
||||
inside a segment's own text.
|
||||
**Step 9 — Assemble the segment outputs.** ref2va/FL2VA: strip each segment text and
|
||||
join with a single `|` (no spaces added around it). Exactly n segments, exactly n−1
|
||||
`|` characters, no trailing separator, no extra headers or numbering; the `|`
|
||||
character must never appear inside a segment's own text. Segmented: instead write
|
||||
each segment to its own `segment-N/segment.txt` file per
|
||||
`references/segmented-output-format.md` — no joined file, no `|` anywhere, and
|
||||
`<Picture N>` / `<Audio N>` written as `@PictureN` / `@AudioN` (`<Subject N>`
|
||||
unchanged).
|
||||
|
||||
**Step 10 — Validate** against the checklist below. When the environment can run Python,
|
||||
also run `python scripts/validate_outputs.py --segments segments.txt --expected-n <n>`
|
||||
(add `--mode fl2va --total-seconds <total>` in FL2VA mode).
|
||||
(add `--mode fl2va --total-seconds <total>` in FL2VA mode; in segmented mode run
|
||||
`python scripts/validate_outputs.py --mode segmented --segments-dir <folder> --expected-n <n>`).
|
||||
|
||||
## Output location
|
||||
|
||||
@ -190,6 +203,10 @@ segment in FL2VA mode, and none in ref2va mode); each is two-key JSON with
|
||||
correct final shot index and two-decimal duration; then `integrated_multimodal_description:`,
|
||||
`overall_soundscape:`, `non_diegetic_music:` in order, and none of the six ref2va
|
||||
section labels appear.
|
||||
12. (Segmented mode) Exactly n `segment-N/segment.txt` files, folders numbered 1..n
|
||||
with no gaps; each file is the ref2va single-segment format with `<Picture N>` /
|
||||
`<Audio N>` written as `@PictureN` / `@AudioN`, `<Subject N>` unchanged, and no `|`
|
||||
character anywhere.
|
||||
|
||||
## References
|
||||
|
||||
@ -197,6 +214,9 @@ section labels appear.
|
||||
default mode (sections, labels, shots, audio template, retention markers).
|
||||
- `references/fl2va-segment-format.md` — the opt-in FL2VA first–last frame prompt
|
||||
format (instruction line, interpolation arc, dialogue and audio rules).
|
||||
- `references/segmented-output-format.md` — the opt-in segmented layout: one
|
||||
`segment-N/segment.txt` file per segment with `@PictureN` / `@AudioN` reference
|
||||
tokens; otherwise identical to the ref2va format.
|
||||
- `references/t2i-character-sheet.md` — the four-panel photorealistic turnaround
|
||||
sheet rules and the two-key JSON output contract.
|
||||
- `references/frame-image-prompts.md` — per-segment first/last frame image prompt
|
||||
|
||||
94
references/segmented-output-format.md
Normal file
94
references/segmented-output-format.md
Normal file
@ -0,0 +1,94 @@
|
||||
# Segmented Output Format (one segment.txt per segment, optional)
|
||||
|
||||
An adaptation of the ref2va format (`references/ref2va-segment-format.md`) for tools
|
||||
that consume one prompt file per segment instead of one joined file. Opt in only when
|
||||
the user asks for it (phrases like "each segment gets its own segment.txt", "one file
|
||||
per segment", "@Picture1", "@Audio1"). Everything not changed below is exactly the
|
||||
ref2va format — same six sections, same summary prefixes, same audio template and
|
||||
lip-sync phrase, same shot rules, same sheets, frame prompts, and manifest. Never mix
|
||||
formats in one run.
|
||||
|
||||
## 1. What changes vs ref2va
|
||||
|
||||
| | ref2va (default) | segmented (opt-in) |
|
||||
| --- | --- | --- |
|
||||
| Output files | one `segments.txt`, n segments joined by bare `\|` | n files: `segment-1/segment.txt`, `segment-2/segment.txt`, ... |
|
||||
| `\|` separators | exactly n−1, bare | none — the `\|` character never appears in any segment file |
|
||||
| Reference tokens | `<Picture 1>`, `<Audio 1>` | `@Picture1`, `@Audio1` |
|
||||
| Subject tokens | `<Subject N>` | `<Subject N>` — unchanged |
|
||||
| Segment content | ref2va single-segment format | identical, one document per file |
|
||||
|
||||
## 2. File layout
|
||||
|
||||
One folder per segment, each containing a file named exactly `segment.txt`:
|
||||
|
||||
```
|
||||
segment-1/segment.txt
|
||||
segment-2/segment.txt
|
||||
...
|
||||
segment-n/segment.txt
|
||||
```
|
||||
|
||||
`segment-N/segment.txt` holds segment N's ref2va document, stripped of leading and
|
||||
trailing whitespace. Folder numbers start at 1 with no gaps and no extra
|
||||
`segment-*` folders. No combined `segments.txt` is written in this mode.
|
||||
|
||||
## 3. Reference token syntax
|
||||
|
||||
Convert every reference token to its @-form — same number, no space, no angle
|
||||
brackets:
|
||||
|
||||
- `<Picture N>` → `@PictureN` (example: `<Picture 1>` → `@Picture1`)
|
||||
- `<Audio N>` → `@AudioN` (example: `<Audio 1>` → `@Audio1`)
|
||||
|
||||
The conversion applies everywhere the token appears: the `subject_definitions`
|
||||
citations and audio definition line, `summary`, `retention_analysis` (including the
|
||||
`fully_copy` line), and the lip-sync phrase inside `detailed_description`. Examples:
|
||||
|
||||
- `<Audio 1> is the user-supplied song file "midnight.mp3", ...` →
|
||||
`@Audio1 is the user-supplied song file "midnight.mp3", ...`
|
||||
- `<Subject 1> lips are synced to the audio in <Audio 1>` →
|
||||
`<Subject 1> lips are synced to the audio in @Audio1`
|
||||
- `<Audio 1>: fully_copy - <Audio 1> is reused 1:1 as the target video's complete
|
||||
final audio track.` → `@Audio1: fully_copy - @Audio1 is reused 1:1 as the target
|
||||
video's complete final audio track.`
|
||||
|
||||
`<Subject N>` is NOT converted: never write `@SubjectN`. The angle-bracket forms
|
||||
`<Picture ...>` and `<Audio ...>` must not appear anywhere in a segmented file.
|
||||
|
||||
## 4. Numbering
|
||||
|
||||
Subject and Picture numbering stays global across the whole video (1..M, gapless when
|
||||
all segment files are taken together), exactly as in ref2va; each file defines only
|
||||
the subjects that appear in it, using their global numbers. `Image-N.json` sheets and
|
||||
`image-map.txt` are unchanged, and `@PictureN` still corresponds to the sheet mapped
|
||||
to Subject N.
|
||||
|
||||
## 5. Worked micro-example
|
||||
|
||||
Segment 1 of the desert project (full end-to-end example in
|
||||
`references/worked-example.md`) as `segment-1/segment.txt` — identical ref2va text,
|
||||
tokens converted:
|
||||
|
||||
```text
|
||||
subject_definitions:
|
||||
<Subject 1> is the astronaut in @Picture1, a woman in her thirties with short black hair, wearing a matte-white EVA suit with orange stripe accents and a wrist-mounted scanner.
|
||||
<Subject 2> is the scout robot in @Picture2, a boxy machine on three wheels with a pale-grey shell and a single round blue lens eye.
|
||||
|
||||
summary:
|
||||
[reference generation] The target video shows <Subject 1> and <Subject 2> cresting a red dune at dusk and stopping before a monolith of black glass. <Subject 1>'s appearance and suit come from @Picture1 and <Subject 2>'s shell and lens come from @Picture2.
|
||||
|
||||
retention_analysis:
|
||||
<Subject 1> (appears in [Shot 1]): fully_preserved - the matte-white EVA suit with orange stripe accents, short black hair, and the wrist-mounted scanner are retained.
|
||||
<Subject 2> (appears in [Shot 1]): fully_preserved - the boxy pale-grey shell, three wheels, and the single round blue lens eye are retained.
|
||||
|
||||
detailed_description:
|
||||
The target video uses a cinematic sci-fi realism style with low dusk light, long violet shadows, and a muted red-and-violet palette.
|
||||
[Shot 1] A wide establishing shot holds on a red desert at dusk, the sky a deep gradient of burnt orange fading into indigo. <Subject 1>, the astronaut in the matte-white EVA suit with orange stripe accents, short black hair under a clear dome, and a wrist-mounted scanner on her left forearm, crests the dune on the left of frame, boots sinking into rippled sand with each step. <Subject 2>, the boxy scout robot with a pale-grey shell and a single round blue lens eye, wheels up the slope on her right, treads leaving a neat triple track. The camera tracks laterally with their descent at walking pace, then slows as the pair reaches the flat basin. Ahead, a monolith of black glass stands three stories tall, its surface drinking the last light; a faint sub-bass hum pushes grit outward from its base in slow pulses. <Subject 1> stops two meters short, raises the wrist scanner, and the device's amber readout reflects in her dome. <Subject 2>'s blue lens dilates with a soft mechanical whir, and its head tilts toward the monolith. The camera pushes in slowly past her shoulder, ending on the monolith's mirrored face holding both their reflections as the hum deepens.
|
||||
|
||||
overall_soundscape:
|
||||
Dry desert wind with fine grit against the helmet shell, the crunch of boots in cooling sand, the soft whir of the robot's wheels, and the monolith's low pulsing hum.
|
||||
|
||||
non_diegetic_music:
|
||||
N/A
|
||||
```
|
||||
@ -288,3 +288,57 @@ same story state as segment 1's last frame (the handoff), worded independently.
|
||||
```json
|
||||
{"expanded_caption": "A photorealistic cinematic film still in 16:9 widescreen showing the same characters as in the supplied character reference images: the astronaut, a woman in her thirties with short black hair and brown eyes, and her scout robot. Wide settled shot at dusk: the two small figures stand still against the towering three-story monolith of black glass now fully lit by slow rivers of amber circuitry light at full brightness climbing its surface, hard orange reflections lying across the woman's clear dome helmet and the robot's pale-grey shell, the woman in the exact matte-white EVA suit with orange stripe accents and grey reinforced gloves, the boxy robot with its single round blue lens eye and short antenna beside her. Fine red dust hangs in a thin widening ring above the basin floor, long violet shadows stretch across the rippled sand, the dusk sky grades from burnt orange into indigo above the monolith's crown, natural skin texture through the dome, true-to-life fabric and rubber texture, sharp focus, single full-bleed frame with no text, no borders, no panels.", "aspect_ratio": "16:9"}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# Segmented variant (one segment.txt per segment, @-references)
|
||||
|
||||
The same desert run in the opt-in segmented layout
|
||||
(`references/segmented-output-format.md`): an adaptation of ref2va where each segment
|
||||
is its own file and reference tokens are written `@PictureN` / `@AudioN`. The segment
|
||||
texts are the Segment 1 / Segment 2 texts from the default run above with only the
|
||||
token syntax converted — content, sections, prefixes, and numbering are unchanged.
|
||||
Sheets, frame prompts, and `image-map.txt` are identical to the default run.
|
||||
|
||||
```
|
||||
segment-1/segment.txt
|
||||
segment-2/segment.txt
|
||||
Image-1.json
|
||||
Image-2.json
|
||||
Segment-img-1.json
|
||||
Segment-img-2.json
|
||||
image-map.txt
|
||||
```
|
||||
|
||||
`segment-1/segment.txt` (segment 2 applies the same conversion to the Segment 2 text
|
||||
above):
|
||||
|
||||
```text
|
||||
subject_definitions:
|
||||
<Subject 1> is the astronaut in @Picture1, a woman in her thirties with short black hair and brown eyes, wearing a matte-white EVA suit with orange stripe accents, grey reinforced gloves, a clear dome helmet, and a wrist-mounted scanner on her left forearm.
|
||||
<Subject 2> is the scout robot in @Picture2, a boxy machine on three wheels with a pale-grey shell, a single round blue lens eye, and a short antenna.
|
||||
|
||||
summary:
|
||||
[reference generation] The target video shows <Subject 1> and <Subject 2> cresting a red dune at dusk and stopping before a monolith of black glass. <Subject 1>'s appearance and suit come from @Picture1 and <Subject 2>'s shell and lens come from @Picture2.
|
||||
|
||||
retention_analysis:
|
||||
<Subject 1> (appears in [Shot 1]): fully_preserved - the matte-white EVA suit with orange stripe accents, grey reinforced gloves, short black hair, clear dome helmet, and the wrist-mounted scanner on her left forearm are retained.
|
||||
<Subject 2> (appears in [Shot 1]): fully_preserved - the boxy pale-grey shell, three wheels, single round blue lens eye, and short antenna are retained.
|
||||
|
||||
detailed_description:
|
||||
The target video uses a cinematic sci-fi realism style with low dusk light, long violet shadows, and a muted red-and-violet palette.
|
||||
[Shot 1] A wide establishing shot holds on a red desert at dusk, the sky a deep gradient of burnt orange fading into indigo. <Subject 1>, the astronaut in the matte-white EVA suit with orange stripe accents, grey reinforced gloves, short black hair under a clear dome helmet, and the wrist-mounted scanner on her left forearm, crests the dune on the left of frame, boots sinking into rippled sand with each step. <Subject 2>, the boxy scout robot with a pale-grey shell, single round blue lens eye, and short antenna, wheels up the slope on her right, treads leaving a neat triple track. The camera tracks laterally with their descent at walking pace, then slows as the pair reaches the flat basin. Ahead, a monolith of black glass stands three stories tall, its surface drinking the last light; a faint sub-bass hum pushes grit outward from its base in slow pulses. <Subject 1> stops two meters short, raises the wrist scanner, and the device's amber readout reflects in her dome. <Subject 2>'s blue lens dilates with a soft mechanical whir and its head tilts toward the monolith. The camera pushes in slowly past her shoulder, ending on the monolith's mirrored face holding both their reflections as the hum deepens.
|
||||
|
||||
overall_soundscape:
|
||||
Dry desert wind with fine grit against the helmet shell, the crunch of boots in cooling sand, the soft whir of the robot's wheels, and the monolith's low pulsing hum.
|
||||
|
||||
non_diegetic_music:
|
||||
N/A
|
||||
```
|
||||
|
||||
Note what did NOT change: `<Subject 1>` keeps its angle brackets (only `<Picture N>`
|
||||
and `<Audio N>` become `@PictureN` / `@AudioN`), there is no `|` character anywhere,
|
||||
and no joined `segments.txt` is written. Validate with
|
||||
`python3 scripts/validate_outputs.py --mode segmented --segments-dir <folder>
|
||||
--expected-n 2`.
|
||||
|
||||
|
||||
@ -10,6 +10,9 @@ Checks the output contract described in SKILL.md:
|
||||
- fl2va mode (opt-in): exact instruction line (final shot index + two-decimal
|
||||
duration), the three fields in order, no reference labels, no ref2va
|
||||
section labels, shot rules, fixed song sentences when a song is reused
|
||||
- segmented mode (opt-in, ref2va adaptation): n files segment-N/segment.txt, no
|
||||
'|' anywhere, @PictureN / @AudioN tokens (angle-bracket <Picture>/<Audio> and
|
||||
@Subject are failures), otherwise the full ref2va per-segment checks
|
||||
- image-map.txt manifest covers every subject; Image-N.json valid (two keys,
|
||||
16:9, four-panel photorealistic sheet language)
|
||||
- Segment-img-N.json per segment (both modes) and Segment-img-N-last.json
|
||||
@ -21,6 +24,8 @@ Usage:
|
||||
python3 scripts/validate_outputs.py --segments segments.txt [--expected-n 3] \
|
||||
[--mode ref2va|fl2va] [--total-seconds 21] [--dir .] [--manifest image-map.txt] \
|
||||
[--lyrics-file lyrics.txt] [--expect-audio]
|
||||
python3 scripts/validate_outputs.py --mode segmented --segments-dir <folder> \
|
||||
[--expected-n 3] [shared options] # folder holds segment-1/segment.txt ...
|
||||
|
||||
Exit code 0 = all checks passed, 1 = failures listed.
|
||||
"""
|
||||
@ -72,6 +77,9 @@ FL2VA_SONG_SENTENCE_RE = re.compile(
|
||||
)
|
||||
FL2VA_LIPSYNC_RE = re.compile(r"\(S(\d+)\) lips stay synced to the song's vocals")
|
||||
|
||||
SEGMENTED_PICTURE_RE = re.compile(r"@Picture(\d+)")
|
||||
SEGMENTED_AUDIO_RE = re.compile(r"@Audio(\d+)")
|
||||
|
||||
BANNED_WORDS = ["cartoon", "anime", "manga", "illustration", "stylized",
|
||||
"cgi", "3d render", "mascot", "avatar", "name tag",
|
||||
"swatch", "palette strip", "design board", "drafting paper"]
|
||||
@ -295,6 +303,23 @@ def check_segment_fl2va(seg_text, seg_no, errors, expected_duration=None):
|
||||
return has_song
|
||||
|
||||
|
||||
def check_segment_segmented(seg_text, seg_no, errors):
|
||||
"""Segmented mode: ref2va content with @-references, one file per segment."""
|
||||
if "|" in seg_text:
|
||||
fail(errors, seg_no, "segmented segment.txt must not contain the '|' "
|
||||
"separator (each segment is its own file)")
|
||||
for bad, good in (("<Picture", "@PictureN"), ("<Audio", "@AudioN")):
|
||||
if bad in seg_text:
|
||||
fail(errors, seg_no, f"segmented files use @-references: '{bad} N' must "
|
||||
f"be written as {good} (no space, no angle brackets)")
|
||||
if "@Subject" in seg_text:
|
||||
fail(errors, seg_no, "subject labels are not converted: keep '<Subject N>', "
|
||||
"never '@SubjectN'")
|
||||
normalized = SEGMENTED_PICTURE_RE.sub(r"<Picture \1>", seg_text)
|
||||
normalized = SEGMENTED_AUDIO_RE.sub(r"<Audio \1>", normalized)
|
||||
return check_segment_ref2va(normalized, seg_no, errors)
|
||||
|
||||
|
||||
def load_two_key_json(fpath, errors):
|
||||
"""Return the parsed object or None; logs contract errors."""
|
||||
try:
|
||||
@ -338,10 +363,15 @@ def check_frame_caption(fname, obj, errors):
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(description=__doc__,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
ap.add_argument("--segments", required=True)
|
||||
ap.add_argument("--segments", required=False, default=None,
|
||||
help="joined segments.txt (not used with --segments-dir)")
|
||||
ap.add_argument("--segments-dir", default=None,
|
||||
help="folder holding segment-1/segment.txt ... (segmented mode)")
|
||||
ap.add_argument("--expected-n", type=int, default=None)
|
||||
ap.add_argument("--mode", choices=["ref2va", "fl2va"], default="ref2va",
|
||||
help="ref2va (default) or fl2va first-last mode")
|
||||
ap.add_argument("--mode", choices=["ref2va", "fl2va", "segmented"],
|
||||
default="ref2va",
|
||||
help="ref2va (default), fl2va first-last, or segmented "
|
||||
"per-file layout")
|
||||
ap.add_argument("--total-seconds", type=float, default=None,
|
||||
help="total video length; enables the S.SS duration check in "
|
||||
"fl2va mode")
|
||||
@ -353,12 +383,53 @@ def main():
|
||||
args = ap.parse_args()
|
||||
|
||||
errors = []
|
||||
if not args.segments and not args.segments_dir:
|
||||
print("FAIL: provide --segments segments.txt or --segments-dir <folder>")
|
||||
return 1
|
||||
if args.segments and args.segments_dir:
|
||||
print("FAIL: use either --segments or --segments-dir, not both")
|
||||
return 1
|
||||
|
||||
if args.segments_dir:
|
||||
if args.mode == "fl2va":
|
||||
print("FAIL: --segments-dir is the segmented layout; use --mode segmented")
|
||||
return 1
|
||||
args.mode = "segmented"
|
||||
seg_dir = Path(args.segments_dir)
|
||||
if not seg_dir.exists():
|
||||
print(f"FAIL: {seg_dir} not found")
|
||||
return 1
|
||||
nums = []
|
||||
for p in seg_dir.iterdir():
|
||||
if p.is_dir() and re.fullmatch(r"segment-\d+", p.name):
|
||||
nums.append(int(p.name.split("-")[1]))
|
||||
elif p.is_dir():
|
||||
errors.append(f"unexpected folder '{p.name}' (expected segment-N)")
|
||||
if not nums:
|
||||
errors.append(f"no segment-N folders with a segment.txt inside found in "
|
||||
f"{seg_dir}")
|
||||
else:
|
||||
if sorted(nums) != list(range(1, len(nums) + 1)):
|
||||
errors.append(f"segment folders must be contiguous segment-1..segment-n "
|
||||
f"(found {sorted(nums)})")
|
||||
if args.expected_n is not None and len(nums) != args.expected_n:
|
||||
errors.append(f"found {len(nums)} segment folder(s), expected "
|
||||
f"{args.expected_n}")
|
||||
parts = []
|
||||
for i in sorted(set(nums)):
|
||||
fpath = seg_dir / f"segment-{i}" / "segment.txt"
|
||||
if not fpath.exists():
|
||||
errors.append(f"missing file: {fpath}")
|
||||
continue
|
||||
parts.append(fpath.read_text(encoding="utf-8").strip())
|
||||
n = len(parts)
|
||||
raw = "\n|\n".join(parts)
|
||||
else:
|
||||
seg_path = Path(args.segments)
|
||||
if not seg_path.exists():
|
||||
print(f"FAIL: {seg_path} not found")
|
||||
return 1
|
||||
raw = seg_path.read_text(encoding="utf-8")
|
||||
|
||||
parts = raw.split("|")
|
||||
n = len(parts)
|
||||
if args.expected_n is not None and n != args.expected_n:
|
||||
@ -377,6 +448,9 @@ def main():
|
||||
for i, part in enumerate(parts, 1):
|
||||
if args.mode == "fl2va":
|
||||
has_audio = check_segment_fl2va(part.strip(), i, errors, expected_duration)
|
||||
elif args.mode == "segmented":
|
||||
defined, has_audio = check_segment_segmented(part.strip(), i, errors)
|
||||
subjects |= defined
|
||||
else:
|
||||
defined, has_audio = check_segment_ref2va(part.strip(), i, errors)
|
||||
subjects |= defined
|
||||
@ -387,7 +461,7 @@ def main():
|
||||
"video references")
|
||||
|
||||
all_nums = set(int(x) for x in SUBJECT_RE.findall(raw))
|
||||
if args.mode == "ref2va" and all_nums and \
|
||||
if args.mode in ("ref2va", "segmented") and all_nums and \
|
||||
all_nums != set(range(1, max(all_nums) + 1)):
|
||||
errors.append(f"global Subject numbering must be gapless 1..{max(all_nums)} "
|
||||
f"(found {sorted(all_nums)})")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user