UNPKG

@calipsa/video-utils

Version:
50 lines (43 loc) 973 B
import ffmpeg, { FfmpegCommand, FfmpegCommandOptions, } from 'fluent-ffmpeg' import { StreamWithBuffer, } from '@calipsa/stream-utils' interface Options { path: string, time: number, ffmpegCommandOptions?: FfmpegCommandOptions, configureFfmpeg?: (ffmpegCommand: FfmpegCommand) => void, } export default async ({ path, time, ffmpegCommandOptions, configureFfmpeg, }: Options) => { const outStream = new StreamWithBuffer() const vcodec = 'mjpeg' return new Promise<Buffer>((resolve, reject) => { const proc = ffmpeg(path, ffmpegCommandOptions) .output(outStream, { end: true, }) .noAudio() .setStartTime(time) .format('image2pipe') .videoCodec(vcodec) .size('640x480') .outputOptions([ '-frames:v 1', '-q:v 2', ]) .on('error', reject) .on('end', () => { resolve(outStream.buffer) }) configureFfmpeg?.(proc) proc.run() }) }