1 changed files with 31 additions and 0 deletions
@ -0,0 +1,31 @@ |
|||||||
|
const express = require("express"); |
||||||
|
const multer = require("multer"); |
||||||
|
const { exec } = require("child_process"); |
||||||
|
const path = require("path"); |
||||||
|
const fs = require("fs"); |
||||||
|
|
||||||
|
const app = express(); |
||||||
|
const upload = multer({ dest: "uploads/" }); |
||||||
|
|
||||||
|
app.post("/convert", upload.fields([{ name: "audio" }, { name: "image" }]), (req, res) => { |
||||||
|
const audioPath = req.files.audio[0].path; |
||||||
|
const imagePath = req.files.image[0].path; |
||||||
|
const output = `output-${Date.now()}.mp4`; |
||||||
|
|
||||||
|
const cmd = `ffmpeg -loop 1 -i ${imagePath} -i ${audioPath} -c:v libx264 -preset fast -tune stillimage -crf 18 -c:a aac -shortest -pix_fmt yuv420p ${output}`; |
||||||
|
|
||||||
|
exec(cmd, (err) => { |
||||||
|
if (err) { |
||||||
|
console.error(err); |
||||||
|
res.status(500).send("Conversion failed"); |
||||||
|
} else { |
||||||
|
res.download(output, () => { |
||||||
|
fs.unlinkSync(audioPath); |
||||||
|
fs.unlinkSync(imagePath); |
||||||
|
fs.unlinkSync(output); |
||||||
|
}); |
||||||
|
} |
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
app.listen(3000, () => console.log("FFmpeg API running on port 3000")); |
||||||
Loading…
Reference in new issue