Files
smartffmpeg/ts/interfaces.ts
2025-12-11 23:03:14 +00:00

186 lines
3.9 KiB
TypeScript

/**
* Video codec options
*/
export type TVideoCodec =
| 'libx264' // H.264
| 'libx265' // H.265/HEVC
| 'libvpx' // VP8
| 'libvpx-vp9' // VP9
| 'libaom-av1' // AV1
| 'mpeg4'
| 'copy' // Copy without re-encoding
| string; // Allow custom codecs
/**
* Audio codec options
*/
export type TAudioCodec =
| 'aac'
| 'libmp3lame' // MP3
| 'libopus' // Opus
| 'libvorbis' // Vorbis
| 'flac'
| 'pcm_s16le' // PCM 16-bit
| 'copy' // Copy without re-encoding
| string; // Allow custom codecs
/**
* Output format/container
*/
export type TOutputFormat =
| 'mp4'
| 'webm'
| 'mkv'
| 'avi'
| 'mov'
| 'flv'
| 'mp3'
| 'wav'
| 'ogg'
| 'flac'
| 'm4a'
| 'gif'
| string;
/**
* Preset for encoding speed/quality tradeoff
*/
export type TPreset =
| 'ultrafast'
| 'superfast'
| 'veryfast'
| 'faster'
| 'fast'
| 'medium'
| 'slow'
| 'slower'
| 'veryslow';
/**
* Media information from ffprobe
*/
export interface IMediaInfo {
format: {
filename: string;
formatName: string;
formatLongName: string;
duration: number;
size: number;
bitrate: number;
};
streams: IStreamInfo[];
}
/**
* Stream information
*/
export interface IStreamInfo {
index: number;
codecName: string;
codecLongName: string;
codecType: 'video' | 'audio' | 'subtitle' | 'data';
width?: number;
height?: number;
frameRate?: number;
bitrate?: number;
sampleRate?: number;
channels?: number;
duration?: number;
}
/**
* Conversion options
*/
export interface IConversionOptions {
/** Output format/container */
format?: TOutputFormat;
/** Video codec */
videoCodec?: TVideoCodec;
/** Audio codec */
audioCodec?: TAudioCodec;
/** Video bitrate (e.g., '1M', '2000k') */
videoBitrate?: string;
/** Audio bitrate (e.g., '128k', '320k') */
audioBitrate?: string;
/** Output width (height auto-scaled if not specified) */
width?: number;
/** Output height (width auto-scaled if not specified) */
height?: number;
/** Frame rate */
fps?: number;
/** Audio sample rate in Hz */
sampleRate?: number;
/** Audio channels (1 for mono, 2 for stereo) */
audioChannels?: number;
/** Encoding preset (speed/quality tradeoff) */
preset?: TPreset;
/** Constant Rate Factor for quality (0-51, lower is better) */
crf?: number;
/** Start time in seconds or timecode string */
startTime?: number | string;
/** Duration in seconds or timecode string */
duration?: number | string;
/** Remove audio track */
noAudio?: boolean;
/** Remove video track */
noVideo?: boolean;
/** Additional ffmpeg arguments */
extraArgs?: string[];
/** Overwrite output file if exists */
overwrite?: boolean;
}
/**
* Progress information during conversion
*/
export interface IProgressInfo {
/** Current frame number */
frame: number;
/** Frames per second being processed */
fps: number;
/** Current quality metric */
q: number;
/** Output file size so far */
size: number;
/** Current time position in seconds */
time: number;
/** Current bitrate */
bitrate: string;
/** Processing speed (e.g., 1.5x realtime) */
speed: string;
/** Progress percentage (0-100) if duration known */
percent?: number;
}
/**
* Screenshot options
*/
export interface IScreenshotOptions {
/** Time position in seconds or timecode string */
time: number | string;
/** Output width */
width?: number;
/** Output height */
height?: number;
/** Output format (default: 'png') */
format?: 'png' | 'jpg' | 'webp';
/** Quality for jpg/webp (1-100) */
quality?: number;
}
/**
* Thumbnail generation options
*/
export interface IThumbnailOptions {
/** Number of thumbnails to generate */
count: number;
/** Output width */
width?: number;
/** Output height */
height?: number;
/** Output format */
format?: 'png' | 'jpg' | 'webp';
/** Filename pattern (use %d for number) */
filenamePattern?: string;
}