186 lines
5.7 KiB
TypeScript
186 lines
5.7 KiB
TypeScript
|
|
import type * as interfaces from './interfaces.js';
|
||
|
|
import { FfmpegCommand, type TFfmpegInput, type IInputOptions } from './classes.ffmpegcommand.js';
|
||
|
|
/**
|
||
|
|
* Event callback types
|
||
|
|
*/
|
||
|
|
export type TProgressCallback = (progress: interfaces.IProgressInfo) => void;
|
||
|
|
export type TErrorCallback = (error: Error) => void;
|
||
|
|
export type TEndCallback = () => void;
|
||
|
|
/**
|
||
|
|
* SmartFfmpeg - A fast Node.js module for media file conversion using ffmpeg
|
||
|
|
*
|
||
|
|
* @example Modern Builder API
|
||
|
|
* ```typescript
|
||
|
|
* const ffmpeg = new SmartFfmpeg();
|
||
|
|
*
|
||
|
|
* // File to file with fluent API
|
||
|
|
* await ffmpeg.create()
|
||
|
|
* .input('/path/to/input.mp4')
|
||
|
|
* .videoCodec('libx264')
|
||
|
|
* .audioBitrate('128k')
|
||
|
|
* .size(1920, 1080)
|
||
|
|
* .output('/path/to/output.mp4')
|
||
|
|
* .run();
|
||
|
|
*
|
||
|
|
* // Buffer to buffer
|
||
|
|
* const outputBuffer = await ffmpeg.create()
|
||
|
|
* .input(inputBuffer, { format: 'mp4' })
|
||
|
|
* .videoCodec('libx264')
|
||
|
|
* .toBuffer('webm');
|
||
|
|
*
|
||
|
|
* // With progress tracking
|
||
|
|
* await ffmpeg.create()
|
||
|
|
* .input('/path/to/input.mp4')
|
||
|
|
* .videoCodec('libx264')
|
||
|
|
* .onProgress(p => console.log(`${p.percent?.toFixed(1)}%`))
|
||
|
|
* .output('/path/to/output.mp4')
|
||
|
|
* .run();
|
||
|
|
*
|
||
|
|
* // Stream output
|
||
|
|
* const stream = ffmpeg.create()
|
||
|
|
* .input('/path/to/input.mp4')
|
||
|
|
* .videoCodec('libx264')
|
||
|
|
* .toStream('mp4');
|
||
|
|
* ```
|
||
|
|
*
|
||
|
|
* @example Legacy API (still supported)
|
||
|
|
* ```typescript
|
||
|
|
* await ffmpeg.convert('input.mp4', 'output.webm', {
|
||
|
|
* videoCodec: 'libvpx-vp9',
|
||
|
|
* audioBitrate: '128k'
|
||
|
|
* });
|
||
|
|
* ```
|
||
|
|
*/
|
||
|
|
export declare class SmartFfmpeg {
|
||
|
|
private ffmpegPath;
|
||
|
|
private ffprobePath;
|
||
|
|
constructor();
|
||
|
|
/**
|
||
|
|
* Create a new FfmpegCommand builder for fluent API usage
|
||
|
|
*
|
||
|
|
* @example
|
||
|
|
* ```typescript
|
||
|
|
* await ffmpeg.create()
|
||
|
|
* .input('/path/to/input.mp4')
|
||
|
|
* .videoCodec('libx264')
|
||
|
|
* .crf(23)
|
||
|
|
* .output('/path/to/output.mp4')
|
||
|
|
* .run();
|
||
|
|
* ```
|
||
|
|
*/
|
||
|
|
create(): FfmpegCommand;
|
||
|
|
/**
|
||
|
|
* Shorthand to create a command with input already set
|
||
|
|
*
|
||
|
|
* @example
|
||
|
|
* ```typescript
|
||
|
|
* // File input
|
||
|
|
* await ffmpeg.input('/path/to/input.mp4')
|
||
|
|
* .videoCodec('libx264')
|
||
|
|
* .output('/path/to/output.mp4')
|
||
|
|
* .run();
|
||
|
|
*
|
||
|
|
* // Buffer input
|
||
|
|
* const output = await ffmpeg.input(buffer, { format: 'mp4' })
|
||
|
|
* .videoCodec('libx264')
|
||
|
|
* .toBuffer('webm');
|
||
|
|
* ```
|
||
|
|
*/
|
||
|
|
input(source: TFfmpegInput, options?: IInputOptions): FfmpegCommand;
|
||
|
|
/**
|
||
|
|
* Get media file information using ffprobe
|
||
|
|
*/
|
||
|
|
getMediaInfo(inputPath: string): Promise<interfaces.IMediaInfo>;
|
||
|
|
/**
|
||
|
|
* Convert media file with specified options
|
||
|
|
*/
|
||
|
|
convert(inputPath: string, outputPath: string, options?: interfaces.IConversionOptions): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Convert media file with progress reporting
|
||
|
|
*/
|
||
|
|
convertWithProgress(inputPath: string, outputPath: string, options?: interfaces.IConversionOptions, onProgress?: TProgressCallback): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Extract audio from video file
|
||
|
|
*/
|
||
|
|
extractAudio(inputPath: string, outputPath: string, options?: Pick<interfaces.IConversionOptions, 'audioCodec' | 'audioBitrate' | 'sampleRate' | 'audioChannels' | 'startTime' | 'duration' | 'overwrite'>): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Remove audio from video file
|
||
|
|
*/
|
||
|
|
removeAudio(inputPath: string, outputPath: string, options?: Pick<interfaces.IConversionOptions, 'videoCodec' | 'videoBitrate' | 'overwrite'>): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Take a screenshot at a specific time
|
||
|
|
*/
|
||
|
|
screenshot(inputPath: string, outputPath: string, options: interfaces.IScreenshotOptions): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Generate multiple thumbnails from video
|
||
|
|
*/
|
||
|
|
generateThumbnails(inputPath: string, outputDir: string, options: interfaces.IThumbnailOptions): Promise<string[]>;
|
||
|
|
/**
|
||
|
|
* Resize video
|
||
|
|
*/
|
||
|
|
resize(inputPath: string, outputPath: string, width?: number, height?: number, options?: Omit<interfaces.IConversionOptions, 'width' | 'height'>): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Change video frame rate
|
||
|
|
*/
|
||
|
|
changeFrameRate(inputPath: string, outputPath: string, fps: number, options?: Omit<interfaces.IConversionOptions, 'fps'>): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Trim media file
|
||
|
|
*/
|
||
|
|
trim(inputPath: string, outputPath: string, startTime: number | string, duration: number | string, options?: Omit<interfaces.IConversionOptions, 'startTime' | 'duration'>): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Convert to GIF
|
||
|
|
*/
|
||
|
|
toGif(inputPath: string, outputPath: string, options?: {
|
||
|
|
width?: number;
|
||
|
|
height?: number;
|
||
|
|
fps?: number;
|
||
|
|
startTime?: number | string;
|
||
|
|
duration?: number | string;
|
||
|
|
}): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Concatenate multiple media files
|
||
|
|
*/
|
||
|
|
concat(inputPaths: string[], outputPath: string, options?: interfaces.IConversionOptions): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Add audio to video
|
||
|
|
*/
|
||
|
|
addAudio(videoPath: string, audioPath: string, outputPath: string, options?: {
|
||
|
|
videoCodec?: interfaces.TVideoCodec;
|
||
|
|
audioCodec?: interfaces.TAudioCodec;
|
||
|
|
audioBitrate?: string;
|
||
|
|
shortest?: boolean;
|
||
|
|
overwrite?: boolean;
|
||
|
|
}): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Get available encoders
|
||
|
|
*/
|
||
|
|
getEncoders(): Promise<string[]>;
|
||
|
|
/**
|
||
|
|
* Get available decoders
|
||
|
|
*/
|
||
|
|
getDecoders(): Promise<string[]>;
|
||
|
|
/**
|
||
|
|
* Get available formats
|
||
|
|
*/
|
||
|
|
getFormats(): Promise<string[]>;
|
||
|
|
/**
|
||
|
|
* Run ffmpeg with raw arguments
|
||
|
|
*/
|
||
|
|
runRaw(args: string[]): Promise<{
|
||
|
|
stdout: string;
|
||
|
|
stderr: string;
|
||
|
|
}>;
|
||
|
|
/**
|
||
|
|
* Run ffprobe with raw arguments
|
||
|
|
*/
|
||
|
|
runProbeRaw(args: string[]): Promise<{
|
||
|
|
stdout: string;
|
||
|
|
stderr: string;
|
||
|
|
}>;
|
||
|
|
private buildConversionArgs;
|
||
|
|
private buildScaleFilter;
|
||
|
|
private formatTime;
|
||
|
|
private parseStreamInfo;
|
||
|
|
private runProcess;
|
||
|
|
}
|