Commit 685ede17 by ramdayalmunda

small size image handling to stretch fixed

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