@opensubtitles/video-metadata-extractor
Version:
A comprehensive NPM package for video metadata extraction and subtitle processing using FFmpeg WASM. Supports metadata extraction, individual subtitle extraction, batch subtitle extraction with ZIP downloads, and memory-safe processing of files of any siz
256 lines • 9.12 kB
TypeScript
/**
* Application constants for video metadata extraction
* Centralizes all configuration values to eliminate duplication and magic numbers
*/
export declare const PROCESSING_CONSTANTS: {
/**
* Chunk sizes for different processing modes (in bytes)
*/
readonly CHUNK_SIZES: {
/** Complete file processing chunk size: 500MB */
readonly COMPLETE_FILE: number;
/** Quick extraction chunk size: 64MB */
readonly QUICK_EXTRACTION: number;
/** Download chunk size: 100MB */
readonly DOWNLOAD: number;
/** Small file threshold: 32MB */
readonly SMALL_FILE_THRESHOLD: number;
/** MKV metadata extraction chunk size: 10MB */
readonly MKV_METADATA_CHUNK: number;
};
/**
* Timeout configurations (in milliseconds)
*/
readonly TIMEOUTS: {
/** File write operation timeout: 30 seconds */
readonly FILE_WRITE: 30000;
/** FFmpeg execution timeout: 60 seconds */
readonly FFMPEG_EXECUTION: 60000;
/** Cleanup operation timeout: 500ms */
readonly CLEANUP: 500;
/** Progressive extraction timeout per chunk: 30 seconds */
readonly PROGRESSIVE_CHUNK: 30000;
};
/**
* Processing limits and thresholds
*/
readonly LIMITS: {
/** Maximum blob size before using chunked download: 2GB */
readonly MAX_BLOB_SIZE: number;
/** Maximum number of progressive chunks for large files */
readonly MAX_PROGRESSIVE_CHUNKS: 10;
/** Large file threshold for special processing: 5GB */
readonly LARGE_FILE_THRESHOLD: number;
/** Very large file threshold: 1GB */
readonly VERY_LARGE_FILE_THRESHOLD: number;
};
/**
* Retry configurations
*/
readonly RETRY: {
/** Maximum number of retry attempts */
readonly MAX_ATTEMPTS: 3;
/** Base delay between retries in milliseconds */
readonly BASE_DELAY: 100;
/** File write retry attempts */
readonly FILE_WRITE_ATTEMPTS: 3;
};
};
export declare const UI_CONSTANTS: {
/**
* UI update delays and timing
*/
readonly DELAYS: {
/** Progress bar update interval: 100ms */
readonly PROGRESS_UPDATE: 100;
/** Batch processing completion display: 3 seconds */
readonly BATCH_COMPLETION_DISPLAY: 3000;
/** Cleanup status display: 2 seconds */
readonly CLEANUP_DISPLAY: 2000;
/** UI blocking prevention during chunking */
readonly CHUNK_UI_DELAY: 10;
};
/**
* Batch processing configurations
*/
readonly BATCH_PROCESSING: {
/** Timeout between batch operations: 60 seconds */
readonly OPERATION_TIMEOUT: 60000;
/** Delay between batch items: 200ms */
readonly ITEM_DELAY: 200;
/** Progress update frequency for batch operations */
readonly PROGRESS_UPDATE_FREQUENCY: 5;
};
/**
* Preview and display limits
*/
readonly DISPLAY: {
/** Maximum characters for subtitle preview */
readonly SUBTITLE_PREVIEW_LENGTH: 200;
/** Maximum items to show in lists */
readonly MAX_LIST_ITEMS: 100;
};
};
/**
* Supported video file formats
* Centralized list to eliminate duplication across files
*/
export declare const SUPPORTED_FORMATS: {
/**
* Video container formats
*/
readonly VIDEO: readonly ["mp4", "m4v", "mov", "3gp", "3g2", "mj2", "avi", "mkv", "webm", "flv", "asf", "wmv", "mpg", "mpeg", "ts", "m2ts", "ogv", "ogg", "gif", "swf", "rm", "rmvb", "dv", "mxf", "nut", "nuv", "roq", "nsv", "wtv", "ty", "pva", "ivf", "yuv", "r3d"];
/**
* Audio formats that may contain video streams
*/
readonly AUDIO: readonly ["aac", "mp3", "flac", "wav", "wv", "ape", "mpc", "tta", "tak", "au", "caf", "w64", "voc", "aiff", "gsm", "amr", "ac3", "eac3", "dts", "dtshd", "truehd", "mlp", "opus", "vorbis", "spx"];
/**
* Subtitle formats
*/
readonly SUBTITLE: readonly ["srt", "ass", "vtt", "sub", "ssa", "webvtt"];
/**
* Get all supported formats as a single array
*/
readonly ALL: ("mp4" | "m4v" | "mov" | "3gp" | "3g2" | "mj2" | "avi" | "mkv" | "webm" | "flv" | "asf" | "wmv" | "mpg" | "mpeg" | "ts" | "m2ts" | "ogv" | "ogg" | "gif" | "swf" | "rm" | "rmvb" | "dv" | "mxf" | "nut" | "nuv" | "roq" | "nsv" | "wtv" | "ty" | "pva" | "ivf" | "yuv" | "r3d" | "aac" | "mp3" | "flac" | "wav" | "wv" | "ape" | "mpc" | "tta" | "tak" | "au" | "caf" | "w64" | "voc" | "aiff" | "gsm" | "amr" | "ac3" | "eac3" | "dts" | "dtshd" | "truehd" | "mlp" | "opus" | "vorbis" | "spx")[];
};
/**
* Language code mapping for subtitle filename generation
* ISO 639-1/639-2 language codes mapped to standardized 2-letter codes
*/
export declare const LANGUAGE_CODES: {
readonly eng: "en";
readonly english: "en";
readonly spa: "es";
readonly spanish: "es";
readonly fre: "fr";
readonly french: "fr";
readonly ger: "de";
readonly german: "de";
readonly ita: "it";
readonly italian: "it";
readonly por: "pt";
readonly portuguese: "pt";
readonly rus: "ru";
readonly russian: "ru";
readonly jpn: "ja";
readonly japanese: "ja";
readonly chi: "zh";
readonly chinese: "zh";
readonly kor: "ko";
readonly korean: "ko";
readonly ara: "ar";
readonly arabic: "ar";
readonly dut: "nl";
readonly dutch: "nl";
readonly swe: "sv";
readonly swedish: "sv";
readonly nor: "no";
readonly norwegian: "no";
readonly dan: "da";
readonly danish: "da";
readonly fin: "fi";
readonly finnish: "fi";
readonly pol: "pl";
readonly polish: "pl";
readonly cze: "cs";
readonly czech: "cs";
readonly hun: "hu";
readonly hungarian: "hu";
readonly gre: "el";
readonly greek: "el";
readonly tur: "tr";
readonly turkish: "tr";
readonly heb: "he";
readonly hebrew: "he";
readonly tha: "th";
readonly thai: "th";
readonly vie: "vi";
readonly vietnamese: "vi";
readonly hin: "hi";
readonly hindi: "hi";
readonly und: "unknown";
readonly unknown: "unknown";
};
/**
* FFmpeg-related constants
*/
export declare const FFMPEG_CONSTANTS: {
/**
* FFmpeg core URLs
*/
readonly CORE_URLS: {
readonly BASE: "https://unpkg.com/@ffmpeg/core@0.12.6/dist/esm";
readonly CORE_JS: string;
readonly WASM: string;
};
/**
* Temporary file names used in FFmpeg virtual filesystem
*/
readonly TEMP_FILES: {
readonly INPUT: "input.video";
readonly OUTPUT: "output.video";
readonly SUBTITLE_SRT: "subtitle.srt";
readonly SUBTITLE_ASS: "subtitle.ass";
readonly SUBTITLE_VTT: "subtitle.vtt";
};
/**
* System directories to preserve during cleanup
*/
readonly SYSTEM_DIRS: Set<string>;
/**
* Default codec parameters
*/
readonly CODECS: {
readonly VIDEO: {
readonly DEFAULT: "libx264";
readonly PRESET: "fast";
readonly CRF: "23";
};
readonly AUDIO: {
readonly DEFAULT: "aac";
readonly BITRATE: "128k";
};
readonly SUBTITLE: {
readonly DEFAULT: "srt";
readonly ENCODING: "UTF-8";
};
};
};
/**
* Error message templates
*/
export declare const ERROR_MESSAGES: {
readonly FFMPEG: {
readonly INIT_FAILED: "Failed to initialize FFmpeg";
readonly EXECUTION_FAILED: "FFmpeg execution failed";
readonly FILE_WRITE_FAILED: "Failed to write file to FFmpeg virtual filesystem";
readonly FILE_READ_FAILED: "Failed to read file from FFmpeg virtual filesystem";
readonly TIMEOUT: "FFmpeg operation timed out";
};
readonly FILE: {
readonly EMPTY: "File appears to be empty";
readonly CORRUPTED: "File appears to be corrupted or not a valid media file";
readonly UNSUPPORTED_FORMAT: "Unsupported file format";
readonly TOO_LARGE: "File size exceeds processing limits";
readonly READ_FAILED: "Failed to read file";
};
readonly SUBTITLE: {
readonly NO_TRACKS: "No subtitle tracks found in this file";
readonly EXTRACTION_FAILED: "Failed to extract subtitle";
readonly INVALID_STREAM: "Invalid subtitle stream index";
readonly EMPTY_RESULT: "No subtitle data could be extracted";
};
readonly NETWORK: {
readonly CONNECTION_FAILED: "Network connection failed";
readonly CORS_ERROR: "CORS error occurred";
readonly FETCH_FAILED: "Failed to fetch resource";
};
};
/**
* Type guard functions for constants
*/
export declare const isValidFormat: (format: string) => format is keyof typeof LANGUAGE_CODES;
export declare const isSupportedVideoFormat: (extension: string) => boolean;
export declare const isSupportedAudioFormat: (extension: string) => boolean;
export declare const isSupportedFormat: (extension: string) => boolean;
//# sourceMappingURL=index.d.ts.map