Reaperxxxx commited on
Commit
77483be
Β·
verified Β·
1 Parent(s): fbc4175

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +16 -10
server.js CHANGED
@@ -3,7 +3,11 @@ const axios = require("axios");
3
  const fs = require("fs");
4
  const path = require("path");
5
  const https = require("https");
6
- const { exec } = require("child_process"); // For FFmpeg execution
 
 
 
 
7
 
8
  const app = express();
9
  const PORT = 7860;
@@ -44,19 +48,21 @@ const scheduleFileDeletion = (filePath, delay = 600000) => {
44
  }, delay);
45
  };
46
 
47
- // Function to convert MKV to MP4 using FFmpeg
48
  const convertToMp4 = (inputPath, outputPath) => {
49
  return new Promise((resolve, reject) => {
50
- const command = `ffmpeg -i "${inputPath}" -c:v copy -c:a aac -strict experimental "${outputPath}"`;
51
- exec(command, (error, stdout, stderr) => {
52
- if (error) {
53
- console.error(`❌ FFmpeg error: ${error.message}`);
54
- reject(error);
55
- } else {
56
  console.log(`βœ… Conversion complete: ${outputPath}`);
57
  resolve(outputPath);
58
- }
59
- });
 
 
 
 
60
  });
61
  };
62
 
 
3
  const fs = require("fs");
4
  const path = require("path");
5
  const https = require("https");
6
+ const ffmpeg = require("fluent-ffmpeg");
7
+ const ffmpegStatic = require("ffmpeg-static");
8
+
9
+ // Set ffmpeg binary path (needed for fluent-ffmpeg)
10
+ ffmpeg.setFfmpegPath(ffmpegStatic);
11
 
12
  const app = express();
13
  const PORT = 7860;
 
48
  }, delay);
49
  };
50
 
51
+ // Function to convert MKV to MP4 using fluent-ffmpeg
52
  const convertToMp4 = (inputPath, outputPath) => {
53
  return new Promise((resolve, reject) => {
54
+ ffmpeg(inputPath)
55
+ .output(outputPath)
56
+ .outputOptions(["-c:v copy", "-c:a aac", "-strict experimental"]) // Fast conversion
57
+ .on("end", () => {
 
 
58
  console.log(`βœ… Conversion complete: ${outputPath}`);
59
  resolve(outputPath);
60
+ })
61
+ .on("error", (err) => {
62
+ console.error(`❌ FFmpeg conversion error: ${err.message}`);
63
+ reject(err);
64
+ })
65
+ .run();
66
  });
67
  };
68