Reaperxxxx commited on
Commit
14fa3d3
Β·
verified Β·
1 Parent(s): 120d1e2

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +18 -3
server.js CHANGED
@@ -41,20 +41,35 @@ const isValidUrl = (url) => {
41
  // Function to convert MKV to MP4 without re-encoding video/audio
42
  const convertToMp4 = (inputPath, outputPath) => {
43
  return new Promise((resolve, reject) => {
44
- console.log(`πŸ”„ Starting conversion: ${inputPath} β†’ ${outputPath}`);
45
-
46
  const ffmpegProcess = ffmpeg(inputPath)
47
  .output(outputPath)
48
- .outputOptions(["-c:v copy", "-c:a copy", "-map 0"]) // Preserve all streams
 
 
 
 
 
 
 
 
49
  .on("end", () => {
50
  console.log(`βœ… Conversion complete: ${outputPath}`);
 
51
  resolve(outputPath);
52
  })
53
  .on("error", (err) => {
54
  console.error(`❌ FFmpeg error: ${err.message}`);
 
55
  reject(err);
56
  })
57
  .run();
 
 
 
 
 
 
 
58
  });
59
  };
60
 
 
41
  // Function to convert MKV to MP4 without re-encoding video/audio
42
  const convertToMp4 = (inputPath, outputPath) => {
43
  return new Promise((resolve, reject) => {
 
 
44
  const ffmpegProcess = ffmpeg(inputPath)
45
  .output(outputPath)
46
+ .outputOptions([
47
+ "-c:v copy", // Copy video without re-encoding
48
+ "-c:a aac", // Ensure audio is converted to AAC
49
+ "-b:a 192k", // Set audio bitrate
50
+ "-strict experimental"
51
+ ])
52
+ .on("start", () => {
53
+ console.log(`πŸ”„ Starting conversion: ${inputPath} β†’ ${outputPath}`);
54
+ })
55
  .on("end", () => {
56
  console.log(`βœ… Conversion complete: ${outputPath}`);
57
+ clearTimeout(timeout);
58
  resolve(outputPath);
59
  })
60
  .on("error", (err) => {
61
  console.error(`❌ FFmpeg error: ${err.message}`);
62
+ clearTimeout(timeout);
63
  reject(err);
64
  })
65
  .run();
66
+
67
+ // Set a timeout to kill FFmpeg if it hangs
68
+ const timeout = setTimeout(() => {
69
+ console.error(`❌ FFmpeg conversion timed out! Killing process.`);
70
+ ffmpegProcess.kill("SIGKILL");
71
+ reject(new Error("❌ Conversion timeout"));
72
+ }, 600000); // 10 minutes timeout
73
  });
74
  };
75