video-optimizer
v1.0.3
Published
Small wrapper around ffmpeg to facilitate interactions; takes arguments as an object, returns a stream.
Readme
Intro
Basically makes FFmpeg easily accessible through an object-based interface and transcodes videos to a stream. No dependencies – except for a local installation of FFmpeg (not part of this package).
Use
Install
npm i video-optimizerImportant: You must have a working installation of FFmpeg available under ffmpeg.
Invoke
import { convertVideo } from 'video-optimizer';
// Will be called when an error happens, which may be heavily asynchronously
const errorCallback = (error: Error): void => { console.error(error); };
// Define where to get and how to transcode the video
const ffmpegArguments = {
source: 'https://fxstr.com/out/test.mp4',
format: 'av1',
height: 720,
width: 1280,
trimStartMs: 1000,
trimEndMs: 2000,
quality: 60,
fps: 20,
keyframeInterval: 10,
};
const { stream } = await convertVideo({ ffmpegArguments, errorCallback });
const chunks: Buffer[] = [];
stream.on('data', (chunk: Buffer): void => { chunks.push(chunk); });
stream.on('end', (): void => {
const result = Buffer.concat(chunks);
console.log('Transcoded video is %d bytes long', result.length);
});Arguments
See the TypeScript definition.
Test it
npm test or npm run test:watch
To test a single file: npm run test:watch -- path/to-file.ts.
To run a single test: npm run test:watch -- -t "name of the test".
Deploy it
npm run publish (makes sure that TypeScript is compiled first)
