-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdebug-batch.js
More file actions
executable file
·114 lines (92 loc) · 2.81 KB
/
debug-batch.js
File metadata and controls
executable file
·114 lines (92 loc) · 2.81 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env node
/**
* Debug script for batch processing
*/
import path from 'path';
import fs from 'fs';
import { batchProcessDirectory, BatchProcessEmitter } from './src/index.js';
// Configuration
const inputDir = './test-videos/input';
const outputDir = './test-videos/output/debug';
const preset = 'web';
// Ensure output directory exists
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
console.log(`Starting batch processing of files in ${inputDir}...`);
console.log(`Output directory: ${outputDir}`);
console.log(`Preset: ${preset}`);
// Create a custom emitter
const customEmitter = new BatchProcessEmitter();
// Add debug event listeners
customEmitter.on('start', (data) => {
console.log('Batch start event:', data);
});
customEmitter.on('progress', (data) => {
console.log('Batch progress event:', data);
});
customEmitter.on('fileStart', (data) => {
console.log('File start event:', data);
});
customEmitter.on('fileProgress', (data) => {
console.log('File progress event:', data);
// Force update to console
process.stdout.write(`Progress: ${data.percent}%\r`);
});
customEmitter.on('fileComplete', (data) => {
console.log('File complete event:', data);
});
customEmitter.on('fileError', (data) => {
console.log('File error event:', data);
});
customEmitter.on('complete', (data) => {
console.log('Batch complete event:', data);
console.log('Batch processing complete!');
console.log(`Processed ${data.total} files: ${data.successful.length} successful, ${data.failed.length} failed`);
if (data.successful.length > 0) {
console.log('\nSuccessfully processed files:');
data.successful.forEach((item, index) => {
console.log(`${index + 1}. ${path.basename(item.input)} → ${path.basename(item.output)}`);
});
}
if (data.failed.length > 0) {
console.log('\nFailed files:');
data.failed.forEach((item, index) => {
console.log(`${index + 1}. ${path.basename(item.input)}: ${item.error}`);
});
}
});
// Batch options
const batchOptions = {
outputDir,
transcodeOptions: {
preset,
overwrite: true
},
concurrency: 1,
emitter: customEmitter // Pass the custom emitter
};
// Scan options
const scanOptions = {
mediaTypes: ['video'],
recursive: false
};
// Start batch processing
async function main() {
try {
console.log('Starting batch processing...');
// Start batch processing with the custom emitter
const { results } = await batchProcessDirectory(inputDir, batchOptions, scanOptions);
// Wait for batch processing to complete
await new Promise(resolve => {
customEmitter.on('complete', () => {
resolve();
});
});
console.log('Batch processing finished!');
} catch (err) {
console.error('Error:', err.message);
process.exit(1);
}
}
main();