Commit 685ede17 by ramdayalmunda

small size image handling to stretch fixed

parent e7fa9a7b
......@@ -14,7 +14,9 @@ const CONFIG = require("../config.js")
const socket = require("../socket.js")
module.exports.generateVideo = async function (req, res) {
let uid;
let _id
let filesCreated = []
try {
let tutorShotData = req.body.tutorShotData;
let videoPath; // local path of the video file
......@@ -24,6 +26,8 @@ module.exports.generateVideo = async function (req, res) {
let updatedData;
if (tutorShotData) {
uid = tutorShotData.uid
_id = tutorShotData._id
let socketPayload = {
uid: tutorShotData.uid,
task: "Video Generation",
......@@ -58,22 +62,25 @@ module.exports.generateVideo = async function (req, res) {
],
{
outputType: "buffer",
dimension: tutorShotData.segments[i].dimension
}
)
let limit = 24 * ((tutorShotData.segments[i]?.duration) ? (tutorShotData.segments[i].duration) : 2);
let frameNum = 0
let firstImage = path.join(imageDir, `${tutorShotData._id}_${frameNumber++}.png`)
await sharp(mergedImage).toFile(firstImage)
imageArr.push(firstImage)
filesCreated.push(firstImage)
do {
let fileName = path.join(imageDir, `${tutorShotData._id}_${frameNumber++}.png`)
imageArr.push(fileName)
filesCreated.push(fileName)
fs.copyFileSync(firstImage, fileName)
} while (++frameNum < limit)
if (i == 0 && thumbnailPath) {
fs.copyFileSync(firstImage, thumbnailPath)
filesCreated.push(thumbnailPath)
}
socketPayload.subTask[0].percent = Math.round(((i+1)/tutorShotData.segments.length)*75); // 75% for generating images
......@@ -92,6 +99,7 @@ module.exports.generateVideo = async function (req, res) {
}
await createVideoFromImages([], options);
filesCreated.push(path.dirname(videoPath))
socketPayload.subTask[0].percent = 100; // 100% if video(without audio) is generated
socketPayload.percent = Math.round( tutorShotData?.audio?.length?socketPayload.subTask[0].percent/2:socketPayload.subTask[0].percent );
socket.emit("videoGenerationProgress", socketPayload);
......@@ -130,7 +138,10 @@ module.exports.generateVideo = async function (req, res) {
res.status(STATUS_CODE.OK).json(tutorShotData)
} catch (err) {
console.log('------ERROR:GENERATING VIDEO', err)
console.log('------ERROR:GENERATING VIDEO')
res.status(STATUS_CODE.ERROR).json()
socket.emit("videoGenerationFailed", { uid, _id })
deleteFile(filesCreated)
}
}
......
......@@ -15,7 +15,7 @@ module.exports.mergeImages = async function (imageArr, options) {
let imageSharp;
if (imageArr[0].url) {
let { data } = await axios.get(imageArr[0].url, { responseType: 'arraybuffer' });
imageSharp = sharp(Buffer.from(data))
imageSharp = sharp(Buffer.from(data)).resize( options.dimension.width, options.dimension.height )
delete data
}
let compositeArr = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment