Update server.js
Browse files
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
|
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
|
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
|
150 |
-
server.timeout =
|
|
|
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;
|