@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
79 lines (78 loc) • 3.02 kB
TypeScript
/**
* Shared FFmpeg Adapter for Video Operations
*
* Centralizes FFmpeg binary resolution, process execution, and temporary file
* management for all video adapter modules (frameExtractor, videoMerger).
*
* Follows the adapter pattern used in `src/lib/adapters/tts/` and
* `src/lib/adapters/providerImageAdapter.ts`.
*
* @module adapters/video/ffmpegAdapter
*/
import { readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
/** Timeout for frame-extraction FFmpeg operations (30 seconds) */
export declare const FFMPEG_FRAME_TIMEOUT_MS = 30000;
/** Timeout for merge/concat FFmpeg operations (2 minutes) */
export declare const FFMPEG_MERGE_TIMEOUT_MS = 120000;
/** Max stdout/stderr buffer for frame extraction (10 MB) */
export declare const FFMPEG_FRAME_MAX_BUFFER: number;
/** Max stdout/stderr buffer for merge operations (50 MB) */
export declare const FFMPEG_MERGE_MAX_BUFFER: number;
/** FFmpeg JPEG quality scale (2 = high quality, range 2-31) */
export declare const JPEG_QUALITY = "2";
/** Seconds before end-of-video to seek when extracting last frame */
export declare const LAST_FRAME_SEEK_OFFSET = "0.5";
/** Minimum valid MP4 buffer size in bytes (ftyp header = 8 bytes minimum) */
export declare const MIN_VIDEO_BUFFER_SIZE = 12;
/**
* Create a tracked temporary directory for FFmpeg operations.
*
* @param prefix - Directory name prefix (e.g. "frame", "merge")
* @returns Absolute path to the created directory
*/
export declare function createTrackedTempDir(prefix: string): Promise<string>;
/**
* Clean up temporary files and their parent directory.
* Logs failures at debug level instead of swallowing silently.
*
* @param tempDir - The temporary directory to remove
* @param files - File paths within tempDir to delete
*/
export declare function cleanupTempFiles(tempDir: string, ...files: string[]): Promise<void>;
/**
* Resolve the FFmpeg binary path.
*
* Resolution order:
* 1. `FFMPEG_PATH` environment variable
* 2. `ffmpeg-static` npm package (optional peer dependency)
* 3. System `ffmpeg` on PATH
*
* @returns Absolute or relative path to the FFmpeg binary
*/
export declare function getFfmpegPath(): Promise<string>;
/**
* Run an FFmpeg command via `child_process.execFile`.
*
* @param args - FFmpeg CLI arguments (without the binary path)
* @param options - Timeout and buffer size overrides
* @returns stdout and stderr from the process
* @throws Error if the process exits with a non-zero code or times out
*/
export declare function runFfmpeg(args: string[], options?: {
timeoutMs?: number;
maxBuffer?: number;
}): Promise<{
stdout: string;
stderr: string;
}>;
/**
* Validate that a buffer looks like a valid MP4 video.
*
* Checks minimum size and the presence of an `ftyp` box header.
*
* @param buffer - Buffer to validate
* @returns `true` if the buffer passes basic MP4 validation
*/
export declare function isValidMp4Buffer(buffer: Buffer): boolean;
export { writeFile, readFile, join };