Update extract.js

This commit is contained in:
Namhyeon Go 2024-02-12 01:02:37 +09:00 committed by GitHub
parent 09f3ae7b90
commit 7a06c65a38
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -41,14 +41,22 @@ function extract(req,res,next) {
let fps = req.query.fps || 1; let fps = req.query.fps || 1;
//compress = zip or gzip //compress = zip or gzip
let compress = req.query.compress || "none"; let compress = req.query.compress || "none";
let download = req.query.download || "no";
let ffmpegParams ={}; let ffmpegParams ={};
var format = "png"; var format = "png";
if (extract === "images"){ if (extract === "images"){
format = "png" format = "png"
ffmpegParams.outputOptions=[]; if (download === "no") {
ffmpegParams.outputOptions.push(`-vf fps=${fps},scale=720:400:force_original_aspect_ratio=decrease`); ffmpegParams.outputOptions=[
ffmpegParams.outputOptions.push(`-f image2`); `-vf fps=${fps}`
ffmpegParams.outputOptions.push(`-frames:v 1`); ];
} else {
ffmpegParams.outputOptions=[
`-vf fps=${fps},scale=720:400:force_original_aspect_ratio=decrease`,
`-f image2`,
`-frames:v 1`
];
}
} }
if (extract === "audio"){ if (extract === "audio"){
format = "wav" format = "wav"
@ -187,12 +195,14 @@ function extract(req,res,next) {
var fileJson={}; var fileJson={};
fileJson["name"] = file; fileJson["name"] = file;
fileJson["url"] = `${req.protocol}://${req.hostname}:${externalPort}${req.baseUrl}/download/${file}`; fileJson["url"] = `${req.protocol}://${req.hostname}:${externalPort}${req.baseUrl}/download/${file}`;
fileJson["base64"] = fs.readFileSync(`/tmp/${file}`, { encoding: 'base64' });
filesArray.push(fileJson); filesArray.push(fileJson);
} }
responseJson["files"] = filesArray; responseJson["files"] = filesArray;
res.status(200).send(responseJson); if (download === "no") {
res.status(200).send(responseJson);
} else {
return utils.downloadFile(`/tmp/${filesArray[0].name}`,null,req,res,next);
}
} }
}) })
.run(); .run();