import type { Nullable } from "../types/index.js"; import type { Readable } from "node:stream"; /** * Options for creating an fMP4 segmenter. */ export interface FMP4SegmenterOptions { initialTrackTimestamps?: Map; onError: (error: Error) => void; onStop: () => void; pendingDiscontinuity?: boolean; previousInitSegment?: Nullable; priorSessionStats?: SessionStats; startingInitVersion?: number; startingSegmentIndex?: number; streamId: number; } /** * Keyframe detection statistics tracked across the lifetime of a segmenter. These metrics provide visibility into the actual keyframe frequency in the fMP4 output, * which is critical for diagnosing frozen screen issues in downstream consumers like Channels DVR. */ export interface KeyframeStats { averageKeyframeIntervalMs: number; indeterminateCount: number; keyframeCount: number; maxKeyframeIntervalMs: number; minKeyframeIntervalMs: number; nonKeyframeCount: number; segmentsWithoutLeadingKeyframe: number; } /** * Session-level statistics accumulated across the lifetime of a stream, including across tab replacements. These metrics provide a summary of segmenter health and A-V * synchronization quality when the stream terminates. */ export interface SessionStats { malformedMoofCount: number; syncSpreadCount: number; syncSpreadMaxMs: number; syncSpreadMinMs: number; syncSpreadSumMs: number; tabReplacementCount: number; } /** * Result of creating an fMP4 segmenter. */ export interface FMP4SegmenterResult { getInitSegment: () => Nullable; getInitVersion: () => number; getKeyframeStats: () => KeyframeStats; getLastSegmentSize: () => number; getSegmentIndex: () => number; getSessionStats: () => SessionStats; getTrackTimestamps: () => Map; markDiscontinuity: () => void; pipe: (stream: Readable) => void; stop: () => void; } /** * Formats keyframe statistics into a human-readable summary for the termination log. Returns an empty string if no moof boxes were processed. The format mirrors the * recovery metrics summary style used in monitor.ts. * * Example output: * - "Keyframes: 2490 of 2490 moofs (100.0%), interval 1.9-2.1s avg 2.0s." * - "Keyframes: 85 of 198 moofs (42.9%), interval 1.8-12.4s avg 3.1s, 5 segments without leading keyframe." * * @param stats - The keyframe statistics to format. * @returns Formatted summary string, or empty string if no data. */ export declare function formatKeyframeStatsSummary(stats: KeyframeStats): string; /** * Formats session statistics into a human-readable summary for the termination log. Returns an empty string if no sync measurements were recorded. The format provides * a concise overview of segmenter health including A-V synchronization, tab replacements, and data integrity. * * Example output: * - "Session: 1725 segments, A-V sync: mean 12.0ms, min 0.7ms, max 25.7ms." * - "Session: 485 segments, A-V sync: mean 10.5ms, min 1.7ms, max 24.3ms, 2 tab replacements." * - "Session: 100 segments, A-V sync: mean 15.2ms, min 2.0ms, max 30.1ms, 1 tab replacement, 3 malformed moofs." * * @param stats - The session statistics to format. * @param segmentCount - Total number of segments produced across all segmenter instances. * @returns Formatted summary string, or empty string if no data. */ export declare function formatSessionStatsSummary(stats: SessionStats, segmentCount: number): string; /** * Creates an fMP4 segmenter that transforms MP4 input into HLS segments. The segmenter parses MP4 boxes, extracts the init segment, detects keyframes in each moof * fragment, and accumulates media fragments into segments based on the configured duration. * @param options - Segmenter options including stream ID and callbacks. * @returns The segmenter interface with pipe, stop, and keyframe stats methods. */ export declare function createFMP4Segmenter(options: FMP4SegmenterOptions): FMP4SegmenterResult;