Reaperxxxx commited on
Commit
120d1e2
Β·
verified Β·
1 Parent(s): 3c65dd1

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +7 -14
server.js CHANGED
@@ -38,30 +38,23 @@ const isValidUrl = (url) => {
38
  }
39
  };
40
 
41
- // Function to convert MKV to MP4
42
  const convertToMp4 = (inputPath, outputPath) => {
43
  return new Promise((resolve, reject) => {
 
 
44
  const ffmpegProcess = ffmpeg(inputPath)
45
  .output(outputPath)
46
- .outputOptions(["-c:v copy", "-c:a aac", "-strict experimental"])
47
  .on("end", () => {
48
  console.log(`βœ… Conversion complete: ${outputPath}`);
49
- clearTimeout(timeout); // Clear timeout when done
50
  resolve(outputPath);
51
  })
52
  .on("error", (err) => {
53
- console.error(`❌ FFmpeg conversion error: ${err.message}`);
54
- clearTimeout(timeout);
55
  reject(err);
56
  })
57
  .run();
58
-
59
- // Set a timeout to kill FFmpeg if it hangs
60
- const timeout = setTimeout(() => {
61
- console.error(`❌ FFmpeg conversion timed out! Killing process.`);
62
- ffmpegProcess.kill("SIGKILL");
63
- reject(new Error("❌ Conversion timeout"));
64
- }, 600000); // 10 minutes timeout
65
  });
66
  };
67
 
@@ -146,5 +139,5 @@ const server = app.listen(PORT, () => {
146
  console.log(`πŸš€ Server running on port ${PORT}`);
147
  });
148
 
149
- // Increase Express server timeout to 10 minutes
150
- server.timeout = 600000;
 
38
  }
39
  };
40
 
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
 
 
139
  console.log(`πŸš€ Server running on port ${PORT}`);
140
  });
141
 
142
+ // Increase Express server timeout to 30 minutes
143
+ server.timeout = 1800000;