ilhamdev commited on
Commit
381b9a4
·
verified ·
1 Parent(s): c03affb

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +12 -3
index.js CHANGED
@@ -20,7 +20,7 @@ let fetch;
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
@@ -38,15 +38,24 @@ async function convertWebmToMp4(webmBuffer) {
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);
46
- ffmpegProcess.stdin.end();
 
 
 
 
47
  });
48
  }
49
 
 
50
  // Menggunakan fungsi konversi sebelum mengonversi ke MP3
51
  async function convertVideoToMp3(videoBuffer) {
52
  try {
 
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
 
38
  chunks.push(chunk); // Accumulate data chunks
39
  });
40
 
41
+ ffmpegProcess.stdin.on('error', (err) => { // Handle errors on stdin
42
+ reject(err);
43
+ });
44
+
45
  ffmpegProcess.on('close', () => {
46
  resolve(Buffer.concat(chunks)); // Concatenate all chunks into a single buffer
47
  });
48
 
49
+ ffmpegProcess.stdin.write(webmBuffer, (err) => { // Write data to stdin
50
+ if (err) {
51
+ reject(err); // If there's an error during writing, reject the promise
52
+ }
53
+ ffmpegProcess.stdin.end(); // End the stdin stream after writing
54
+ });
55
  });
56
  }
57
 
58
+
59
  // Menggunakan fungsi konversi sebelum mengonversi ke MP3
60
  async function convertVideoToMp3(videoBuffer) {
61
  try {