-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrimmp4.ts
35 lines (30 loc) · 924 Bytes
/
trimmp4.ts
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
30
31
32
33
34
35
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
const ffmpeg = require('fluent-ffmpeg');
const glob = require('glob');
const fs = require('fs');
ffmpeg.setFfmpegPath(ffmpegPath);
/******************** CONFIG ********************
startTime: when do you want the new start time to be (hh:mm:ss)
clipDuration: how long do you want the clip to be in seconds (e.g. 30)
Change the consts below to the desired naming you want.
*/
const startTime: string = '00:02:30';
const clipDuration: number = 30;
glob(`*.mp4`, (_, clips) => {
clips.forEach((clip, i) => {
ffmpeg(clip)
.setStartTime(startTime)
.setDuration(clipDuration)
.output(`${clip}_${i}.mp4`)
.on('end', err => {
if (!err) {
console.log(`${clip} converted`);
fs.unlinkSync(clip);
}
})
.on('error', err => {
console.error(err);
})
.run();
});
});