import { type RunFfmpegOptions } from './ffmpeg.js'; import { type ConcatStrategy } from './stitch-concat.js'; import { type AudioLayer } from './stitch-audio-mix.js'; export { FILTER_FALLBACK_SEGMENT_THRESHOLD, DEFAULT_MUSIC_VOLUME, DEFAULT_MUSIC_FADE_OUT_SEC, STANDARD_AUDIO_BITRATE, GRADE_FILTER_IDS, ON_TWOS_FILTER, DEFAULT_FILM_GRAIN, SHARPEN_FILTER, filmGrainFilter, resolveGradeFilter } from './stitch-filters.js'; export { orderedSegments, selectConcatStrategy, buildConcatListContent, buildConcatDemuxerArgs, buildConcatFilterArgs, buildSegmentPrepArgs } from './stitch-concat.js'; export type { ConcatStrategy, BuildConcatFilterOptions, BuildSegmentPrepOptions } from './stitch-concat.js'; export { buildMultiLayerMixArgs } from './stitch-audio-mix.js'; export type { AudioLayer, BuildMultiLayerMixOptions } from './stitch-audio-mix.js'; export interface MusicMixSettings { /** Path to the background-music track. Looped under the narration. */ trackPath: string; /** Mix level for the music bed (0..1). Defaults to {@link DEFAULT_MUSIC_VOLUME}. */ volume?: number; /** Tail fade-out duration in seconds. Defaults to {@link DEFAULT_MUSIC_FADE_OUT_SEC}. */ fadeOutSec?: number; /** * Voice-forward mix (loudnorm the video's narration + sidechain-duck the music * under it + final limiter). Forwarded to {@link BuildMusicMixOptions.voiceForward}. * Default off → byte-identical legacy bed mix. */ voiceForward?: boolean; } export interface StitchInput { /** * Ordered body segment paths (the slide segments). These sit between the * optional intro and outro segments. From 3e every segment conforms to * 1280×720@24 / H.264 / AAC 44100 stereo, so demuxer concat is valid. */ segments: string[]; /** Optional ordered intro segment paths, prepended before `segments`. */ intro?: string[]; /** Optional ordered outro segment paths, appended after `segments`. */ outro?: string[]; /** Where the final stitched MP4 is written. */ outputPath: string; /** * Path for the concat-demuxer list file. Defaults to `concat.txt` alongside * the output. Only used by the demuxer path. */ concatListPath?: string; /** * Concat strategy. `auto` (default) uses the demuxer up to * {@link FILTER_FALLBACK_SEGMENT_THRESHOLD} segments, then the filter. * bunty maps to `auto`/`demuxer`; nex maps to `filter`. */ concatStrategy?: ConcatStrategy; /** * Whole-cut finishing look, applied in the per-segment prep pass. All three * default off, so omitting them leaves the emitted ffmpeg args byte-identical. * Unlike `segmentGradeIds` these are not per-scene: they are the pass that * binds every generation into one cohesive piece. */ onTwos?: boolean; sharpen?: boolean; filmGrain?: number; /** Optional background-music bed (the nex-brand knob). Omit for bunty. */ music?: MusicMixSettings; /** * Optional EXTRA global audio layers (dialogue / sfx / additional voice) * mixed over the concatenated video at the stitch step, BEYOND the `music` * bed above. Presence-driven and additive: when this is empty/undefined the * stitch is byte-identical to legacy (the music-only {@link buildMusicMixArgs} * path, or the no-audio path). When non-empty, the music bed (if any) is * prepended as a `music` layer and the whole set is mixed via * {@link buildMultiLayerMixArgs}. See assemble.ts Step 6 (dialogue/sfx wiring). */ audioLayers?: AudioLayer[]; /** * Sidechain-duck every `music` layer under the narration/dialogue layers in * the MULTI-LAYER mix (`audioLayers` path). The multi-layer analogue of * `music.voiceForward`: without it a soundtrack bed sits at full level over * a narration layer. Only consulted when `audioLayers` is non-empty; unset → * byte-identical legacy multi-layer mix. */ duckMusicUnderVoice?: boolean; /** * Drop the concatenated segments' own audio from the final mix — the * silent-film switch. assemble sets this when every scene is marked * `silent`, because on `veo-useapi` there is no way to ask the provider for * a silent clip: Veo 3.x is audio-native and the Flow API has no audio-off * parameter, so `generateAudio: false` is a promise the route cannot keep. * Stripping here is the only place the intent can actually be enforced. * Unset → byte-identical legacy mix. */ dropSegmentAudio?: boolean; /** * Segment indices whose audio is silenced, leaving the rest of the film's * audio intact. Indices are into the ORDERED segment list (intro/outro * included), matching `segmentGradeIds`. Prefer this over * {@link dropSegmentAudio} whenever the problem is confined to known shots — * it costs one shot's ambience rather than the whole film's. */ muteSegmentAudio?: number[]; /** * Optional per-clip tail cut (WS9). When set, each ordered segment is * re-encoded with `-t ` before concat, dropping the dead / * freeze frames AI generators append. Omit for byte-identical legacy behavior. */ clipMaxSeconds?: number; /** * Optional letterbox normalization (WS9). When set (e.g. `2.39:1`), each * segment is scaled+padded onto the {@link letterboxCanvas} (default * 1280×720) before concat, producing cinematic bars. Omit to disable. */ letterboxRatio?: string; /** * Canvas for {@link letterboxRatio}. Defaults to the 3e segment standard * (1280×720) so normalized segments stay uniform for demuxer concat. */ letterboxCanvas?: { width: number; height: number; }; /** * Path to a `.cube`/`.3dl` LUT applied to every segment via `lut3d` (e.g. a * Kodak Vision3 500T film-stock LUT). Omit to skip. Triggers the prep pass. */ gradeLut?: string; /** * Named color grade applied to every segment (see {@link GRADE_FILTER_IDS}). * A real post transform on the footage, not a prompt hint. Omit to skip. */ gradeId?: string; /** * Per-segment grade overrides, indexed to {@link orderedSegments} (intro + * body + outro). A defined entry overrides {@link gradeId} for that segment — * this is how the narrative color language is realized (e.g. cool-steel for the * calm scenes, crimson-threat for the breach, electric-blue for the resolution). */ segmentGradeIds?: Array; /** * Optional reading-holds (motion-comic). For each listed segment index (into * {@link orderedSegments}: intro+body+outro), a short held, gently-drifting * still of that segment's readable FIRST frame is prepended BEFORE its motion * plays — so viewers can read text-dense info panels (a cast roster, a strategy * map) before the animation takes over. Omit / empty `segments` → byte-identical * legacy (no holds). When any hold is present the concat uses the FILTER path * (re-encode) so the freshly-encoded hold clips concat cleanly with the segments. */ readingHold?: ReadingHoldSettings; } export interface ReadingHoldSettings { /** Hold duration in seconds before each designated segment. Default 3.5. */ holdSec?: number; /** Segment indices (into orderedSegments) that get a reading hold. Empty ⇒ no holds. */ segments: number[]; } export interface BuildReadingHoldOptions { /** Hold duration in seconds. Default 3.5. */ holdSec?: number; /** Output width. Default 1280. */ width?: number; /** Output height. Default 720. */ height?: number; /** Output fps. Default 24. */ fps?: number; } /** * Build ffmpeg args (PURE) that turn a video segment's FIRST frame into a short * held, gently-drifting still clip (a "reading hold"), with a silent stereo audio * track so it concats cleanly. `select=eq(n,0)` grabs frame 0; `zoompan` holds it * for `holdSec` with a faint slow zoom (alive, not frozen); encoded to the segment * standard (libx264 crf20 / AAC 44100 stereo @ fps). `-y` is prepended by runFfmpeg. */ export declare function buildReadingHoldArgs(segmentPath: string, outputPath: string, opts?: BuildReadingHoldOptions): string[]; export interface StitchPlannedStep { /** What this step does. */ kind: 'segment-prep' | 'reading-hold' | 'concat-demuxer' | 'concat-filter' | 'music-mix' | 'multi-layer-mix'; /** The ffmpeg args (everything after the binary and the auto-prepended `-y`). */ args: string[]; /** The output this step writes. */ outputPath: string; } export interface StitchResult { status: 'complete' | 'dry-run'; /** Final MP4 path. */ outputPath: string; /** Ordered list of every segment that went into the concat. */ orderedSegments: string[]; /** Which concat path was actually used. */ concatStrategy: 'demuxer' | 'filter'; /** Whether a music bed was mixed. */ music: boolean; /** The planned ffmpeg command sequence (always populated, incl. dry-run). */ plan: StitchPlannedStep[]; /** Final video duration in milliseconds (0 on dry-run — no probe). */ durationMs: number; } export interface BuildMusicMixOptions { /** Mix level for the music bed (0..1). Default {@link DEFAULT_MUSIC_VOLUME}. */ volume?: number; /** Tail fade-out seconds. Default {@link DEFAULT_MUSIC_FADE_OUT_SEC}. */ fadeOutSec?: number; /** * Total video duration in seconds — used to compute the fade-out start * (`total - fadeOut`) and the `-t` cap. The caller probes this via * `ffprobeDuration`. Defaults to 0 (fade starts at 0 / `-t 0`), only used by * the dry-run / pure-builder path where the duration is not yet known. */ totalDurationSec?: number; /** * Voice-forward mix (default false → byte-identical legacy). When true, the * video's own audio (`[0:a]`, i.e. the baked per-scene narration) is loudnorm'd * to a broadcast target, the music bed is sidechain-ducked under it, and the * final mix is limited — so narration is never buried beneath the bed. This is * the film-proven chain (loudnorm I=-15:TP=-1.5 + sidechaincompress + alimiter). * assemble enables it by default whenever per-scene narration was produced. */ voiceForward?: boolean; /** * Drop the video's own audio (`[0:a]`) so the bed plays over a genuinely * silent picture. See {@link BuildMultiLayerMixOptions.dropVideoAudio} — same * reason, the music-only path. Mutually exclusive with `voiceForward`, which * exists to keep the clip's voice audible; when both are set `dropVideoAudio` * wins, because "this film has no voice" is the stronger statement. * Default `false` → byte-identical legacy graph. */ dropVideoAudio?: boolean; /** * Whether the video input actually carries an audio stream. Default `true` * → byte-identical legacy graph. `stitch()` probes the concat on a real run * and passes `false` for a silent picture, in which case the bed is the whole * mix: referencing `[0:a]` on an audioless input is an ffmpeg failure. The * existing `-t` cap already bounds the looped bed. See * {@link BuildMultiLayerMixOptions.videoHasAudio}. */ videoHasAudio?: boolean; } /** * Build the background-music mix ffmpeg args (PURE). Loops the music under the * narration at a low volume with a tail fade-out, then mixes via amix. * * Ported VERBATIM from assembly_utils.add_background_music (L408-435): * -i video -stream_loop -1 -i music * -filter_complex "[0:a]volume=1.0[v]; * [1:a]volume={vol},afade=t=out:st={fade_start}:d={fade_out}[m]; * [v][m]amix=inputs=2:duration=first:dropout_transition=600:normalize=0[a]" * -map 0:v -map [a] * -c:v copy -c:a aac -b:a 192k * -movflags +faststart * -t {total} output * * fade_start = max(0, total - fade_out). `dropout_transition=600` prevents early * audio cutoff on silent sections; `normalize=0` keeps the narration at full * level while the music stays at `volume`. */ export declare function buildMusicMixArgs(videoPath: string, musicPath: string, outputPath: string, opts?: BuildMusicMixOptions): string[]; export interface StitchOptions extends RunFfmpegOptions { /** Override the ffprobe binary (forwarded to `ffprobeDuration`). */ ffprobeBin?: string; /** * Skip the pre-concat MP4-validity guard. Default OFF (validation ON) for * real runs. The guard probes each input segment with {@link isValidMp4} and * fails fast on a truncated/no-moov MP4 instead of letting ffmpeg concat die * with a cryptic "Invalid data found when processing input". Always skipped on * dry-run (no real files to probe). */ skipSegmentValidation?: boolean; } /** * Orchestrate the stitch: write the concat list (demuxer path), pick the * demuxer-vs-filter path, run via `runFfmpeg`, optionally mix a music bed, and * return the final MP4 path + a plan of the executed command sequence. * * On `dryRun`, returns the planned command sequence WITHOUT writing the concat * list, spawning ffmpeg, or probing durations (music fade-start is computed * from 0). This is the path unit tests use. * * NOTE: the real-spawn path. The final-MP4 quality check is a HUMAN integration * checkpoint — out of scope here. */ export declare function stitch(input: StitchInput, opts?: StitchOptions): Promise; //# sourceMappingURL=stitch.d.ts.map