UNPKG

@calipsa/video-utils

Version:
51 lines (43 loc) 1.11 kB
import ffmpeg, { FfmpegCommandOptions, FfmpegCommand, } from 'fluent-ffmpeg' import { StreamWithFrames, } from '@calipsa/stream-utils' interface Options { path: string, rate: number, format: 'jpg' | 'png', ffmpegCommandOptions?: FfmpegCommandOptions, configureFfmpeg?: (ffmpegCommand: FfmpegCommand) => void, } export default async ({ path, rate = 1, format = 'jpg', ffmpegCommandOptions, configureFfmpeg, }: Options) => new Promise<Buffer[]>((resolve, reject) => { const outStream = new StreamWithFrames(rate) const vcodec = format === 'png' ? 'png' : 'mjpeg' const proc = ffmpeg(path, ffmpegCommandOptions) .output(outStream, { end: true, }) .noAudio() .format('image2pipe') // -f .videoCodec(vcodec) // -vcodec .size('640x480') .outputOption('-q:v', '2') .on('error', reject) // .on('start', commandLine => { // console.log(`Spawned Ffmpeg with command: ${commandLine}`) // }) .on('end', () => { resolve(outStream.buffers) }) configureFfmpeg?.(proc) proc.run() })