npm i fluent-ffmpeg
To use the same codec and avoid re encoding all the video, simply pass copy
as argument in withVideoCodec
and withAudioCodec
:
index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
const ffmpeg = require('fluent-ffmpeg'); const pathToFfmpeg = require('ffmpeg-static'); const ffprobe = require('ffprobe-static'); const cutVideo = async (sourcePath, outputPath, startTime, duration) => { console.log('start cut video'); await new Promise((resolve, reject) => { ffmpeg(sourcePath) .setFfmpegPath(pathToFfmpeg) .setFfprobePath(ffprobe.path) .output(outputPath) .setStartTime(startTime) .setDuration(duration) .withVideoCodec('copy') .withAudioCodec('copy') .on('end', function (err) { if (!err) { console.log('conversion Done'); resolve(); } }) .on('error', function (err) { console.log('error: ', err); reject(err); }) .run(); }); }; |