ffmpeg-toolkit
Version:
A modern FFmpeg toolkit for Node.js
190 lines • 5.76 kB
TypeScript
/**
* Core type definitions for the FFmpeg toolkit
*/
import { FfmpegCommand } from 'fluent-ffmpeg';
export type Status = 'idle' | 'processing' | 'completed' | 'error' | 'success';
export interface BaseResponse<T> {
status: Status;
message: string;
data: T | null;
}
export type Platform = 'original' | 'youtube' | 'youtube_short' | 'tiktok' | 'instagram_reel' | 'instagram_story' | 'instagram_post' | 'linkedin_9_16' | 'linkedin_1_1' | 'x_twitter' | 'facebook_video' | 'facebook_story' | 'facebook_post' | 'snapchat' | 'tall_portrait' | 'portrait' | 'square' | 'landscape' | 'wide_landscape';
export type PlatformDimension = Record<Platform, {
aspectRatio: string;
}>;
export interface VideoInfo {
width: number;
height: number;
fps: number;
bitrate: number;
codec: string;
colorSpace: string;
format?: string;
duration?: number;
size?: number;
streams?: StreamInfo[];
}
export interface StreamInfo {
codec_type: 'video' | 'audio' | 'subtitle';
codec_name: string;
width?: number;
height?: number;
sample_rate?: number;
channels?: number;
language?: string;
fps?: number;
}
export interface FFmpegConfig {
ffmpegPath?: string;
ffprobePath?: string;
threads?: number;
timeout?: number;
logger?: boolean;
}
export interface FFmpegOptions {
threads?: number;
bufsize?: string;
maxrate?: string;
preset?: string;
tune?: string;
cpuUsed?: number;
fps?: number;
customOptions?: string[];
inputOptions?: string[];
}
export interface ProcessOptions<T, K, E> {
callback: () => FfmpegCommand;
onEnd?: (_stdout?: string | null, _stderr?: string | null) => Promise<K>;
onError?: (_err: Error, _stdout: string | null, _stderr: string | null) => Promise<E>;
onProgress?: (_progress: ProgressEvent) => Promise<K>;
pathOutput?: string;
data: T;
platform?: Platform;
inputPath?: string;
isDefaultOptions?: boolean;
}
export interface ProgressEvent {
percent?: number;
frames: number;
currentFps: number;
targetSize: number;
timemark: string;
}
export interface CoreConfig {
timeout?: number;
logger?: boolean;
loggerPath?: string;
threads?: number;
rootOutput?: string;
}
export interface CoreState {
status: Status;
lastUpdated: Date;
error?: string;
progress?: number;
}
export type FFmpegEventType = 'start' | 'progress' | 'end' | 'error';
export interface ConversionOptions {
format: string;
videoCodec?: string;
audioCodec?: string;
videoBitrate?: string;
audioBitrate?: string;
resolution?: string;
fps?: number;
startTime?: number;
duration?: number;
preset?: 'ultrafast' | 'superfast' | 'veryfast' | 'faster' | 'fast' | 'medium' | 'slow' | 'slower' | 'veryslow';
crf?: string;
movflags?: string;
tune?: 'film' | 'animation' | 'grain' | 'stillimage' | 'fastdecode' | 'zerolatency';
hwaccel?: 'auto' | 'cuda' | 'dxva2' | 'qsv' | 'vaapi';
threads?: number;
}
export interface SubtitleOptions {
format: 'srt' | 'ass' | 'vtt';
language?: string;
encoding?: string;
}
export interface FrameProcessingOptions {
platform: Platform;
frameRate?: number;
quality?: number;
format?: 'jpg' | 'png' | 'webp';
maxWidth?: number;
maxHeight?: number;
outputDir?: string;
}
export interface FrameInfo {
index: number;
timestamp: number;
path: string;
size: number;
width: number;
height: number;
}
export type VideoExtension = 'mp4' | 'mkv' | 'webm' | 'mov' | 'avi' | 'flv' | 'ts' | 'm4v' | 'mpeg' | 'mpg';
export type ImageExtension = 'jpg' | 'jpeg' | 'png' | 'gif' | 'bmp' | 'webp' | 'tiff' | 'ico';
export type AudioExtension = 'mp3' | 'wav' | 'aac' | 'ogg' | 'wma' | 'flac' | 'm4a' | 'aiff' | 'alac' | 'opus';
export interface BaseOptions {
inputPath: string;
pathOutput: string;
}
export interface BaseConvertOptions extends BaseOptions {
outputFormat: ImageExtension | AudioExtension;
}
export interface BaseDimensionOptions extends BaseOptions {
width: number;
height: number;
}
export interface BaseMultiInputOptions extends BaseOptions {
inputPaths: string[];
}
export interface CropVideoOptions extends BaseDimensionOptions {
duration?: number;
}
export interface ConvertVideoToPlatformOptions extends BaseOptions {
platform: Platform;
}
export type ConcatVideosOptions = Omit<BaseMultiInputOptions, 'inputPath'> & {
isNoAudio?: boolean;
};
export interface ConcatVideosWithTransitionOptions extends Omit<BaseMultiInputOptions, 'inputPath'> {
transitionDuration?: number;
transitionType?: 'fade' | 'wipe' | 'dissolve' | 'slide' | 'zoom' | 'rotate' | 'pixelate';
}
export interface ConvertImageOptions extends BaseConvertOptions {
outputFormat: ImageExtension;
}
export type ResizeImageOptions = BaseDimensionOptions;
export interface ExtractThumbnailOptions extends BaseOptions {
time: number;
}
export interface ImageToVideoOptions extends BaseOptions {
duration: number;
}
export type ConcatAudiosOptions = Omit<BaseMultiInputOptions, 'inputPath'>;
export interface MergeAudioToVideoOptions extends BaseOptions {
audioPath: string;
volume?: number;
isNoAudio?: boolean;
}
export interface ConvertAudioOptions extends BaseConvertOptions {
outputFormat: AudioExtension;
}
export interface BurnSubtitlesOptions extends BaseOptions {
subtitlesPath: string;
fontDirectory?: string;
}
export interface AudioSettings {
format: string;
codec: string;
bitrate: string;
options?: string[];
}
export interface ImageSettings {
format: string;
codec: string;
options: string[];
}
//# sourceMappingURL=ffmpeg.d.ts.map