Update index.js
Browse files
index.js
CHANGED
|
@@ -20,7 +20,7 @@ let fetch;
|
|
| 20 |
const ffmpeg = require('fluent-ffmpeg');
|
| 21 |
const { spawn } = require('child_process');
|
| 22 |
|
| 23 |
-
function convertWebmToMp4(webmBuffer) {
|
| 24 |
return new Promise((resolve, reject) => {
|
| 25 |
const ffmpegProcess = spawn('ffmpeg', [
|
| 26 |
'-i', '-', // Input dari stdin
|
|
@@ -28,12 +28,18 @@ function convertWebmToMp4(webmBuffer) {
|
|
| 28 |
'pipe:1' // Output ke stdout
|
| 29 |
]);
|
| 30 |
|
|
|
|
|
|
|
| 31 |
ffmpegProcess.on('error', (err) => {
|
| 32 |
reject(err);
|
| 33 |
});
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
ffmpegProcess.on('close', () => {
|
| 36 |
-
resolve(Buffer.concat(chunks));
|
| 37 |
});
|
| 38 |
|
| 39 |
ffmpegProcess.stdin.write(webmBuffer);
|
|
|
|
| 20 |
const ffmpeg = require('fluent-ffmpeg');
|
| 21 |
const { spawn } = require('child_process');
|
| 22 |
|
| 23 |
+
async function convertWebmToMp4(webmBuffer) {
|
| 24 |
return new Promise((resolve, reject) => {
|
| 25 |
const ffmpegProcess = spawn('ffmpeg', [
|
| 26 |
'-i', '-', // Input dari stdin
|
|
|
|
| 28 |
'pipe:1' // Output ke stdout
|
| 29 |
]);
|
| 30 |
|
| 31 |
+
let chunks = []; // Define chunks array to accumulate data
|
| 32 |
+
|
| 33 |
ffmpegProcess.on('error', (err) => {
|
| 34 |
reject(err);
|
| 35 |
});
|
| 36 |
|
| 37 |
+
ffmpegProcess.stdout.on('data', (chunk) => { // Listen for data events from stdout
|
| 38 |
+
chunks.push(chunk); // Accumulate data chunks
|
| 39 |
+
});
|
| 40 |
+
|
| 41 |
ffmpegProcess.on('close', () => {
|
| 42 |
+
resolve(Buffer.concat(chunks)); // Concatenate all chunks into a single buffer
|
| 43 |
});
|
| 44 |
|
| 45 |
ffmpegProcess.stdin.write(webmBuffer);
|