You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
988 B
31 lines
988 B
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"));
|
|
|