-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepareTestData.ts
50 lines (43 loc) · 1.41 KB
/
prepareTestData.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import fs from 'fs';
import path from 'path';
import ffmpeg from 'fluent-ffmpeg';
const sourceFolder = '/path/to/first/folder';
const mixFolder = '/path/to/second/folder';
const outputFolder = '/path/to/output/folder';
// Read files in the mixFolder directory
fs.readdir(mixFolder, (err, files) => {
if (err) {
console.error('Error reading mixFolder directory:', err);
return;
}
// Process each file
files.forEach(file => {
const mixFilePath = path.join(mixFolder, file);
const outputFilePath = path.join(outputFolder, file.replace('.mp4', '.mp3'));
// Check if the output file already exists
if (fs.existsSync(outputFilePath)) {
console.log(`File ${outputFilePath} already exists. Skipping.`);
return;
}
// Change the file extension from .mp4 to .mp3
const audioFileName = file.replace('.mp4', '.mp3');
const audioFilePath = path.join(sourceFolder, audioFileName);
// Check if the audio file exists
if (!fs.existsSync(audioFilePath)) {
console.log(`Audio file ${audioFilePath} does not exist. Skipping.`);
return;
}
// Mix the video file with the audio
ffmpeg()
.input(mixFilePath)
.input(audioFilePath)
.output(outputFilePath)
.on('end', () => {
console.log(`Created ${outputFilePath}`);
})
.on('error', err => {
console.error('Error mixing files:', err);
})
.run();
});
});