Commit 8107f789 by ramdayalmunda

progress bar handling while generating video

parent 685ede17
...@@ -17,24 +17,25 @@ module.exports.generateVideo = async function (req, res) { ...@@ -17,24 +17,25 @@ module.exports.generateVideo = async function (req, res) {
let uid; let uid;
let _id let _id
let filesCreated = [] let filesCreated = []
let socketPayload
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
let thumbnailPath // local path of the thumbnail file let thumbnailPath // local path of the thumbnail file
let fileName; // remote name of the final video file let fileName; // remote name of the final video file
let thumbnailName; // remote name of the final thumbnail let thumbnailName; // remote name of the final thumbnail
let updatedData;
if (tutorShotData) { if (tutorShotData) {
uid = tutorShotData.uid uid = tutorShotData.uid
_id = tutorShotData._id _id = tutorShotData._id
let socketPayload = { socketPayload = {
uid: tutorShotData.uid, uid: tutorShotData.uid,
_id: tutorShotData._id,
task: "Video Generation", task: "Video Generation",
percent: 0, percent: 0,
subTask: [ { task: "Image Compiled", percent: 0 } ] subTask: [{ task: "Image Compiled", percent: 0 }]
} }
if ( tutorShotData?.audio?.length ){ if (tutorShotData?.audio?.length) {
socketPayload.subTask.push({ task: "Audio mixing", percent: 0 }) socketPayload.subTask.push({ task: "Audio mixing", percent: 0 })
} }
...@@ -83,8 +84,8 @@ module.exports.generateVideo = async function (req, res) { ...@@ -83,8 +84,8 @@ module.exports.generateVideo = async function (req, res) {
filesCreated.push(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
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);
} }
...@@ -101,7 +102,7 @@ module.exports.generateVideo = async function (req, res) { ...@@ -101,7 +102,7 @@ module.exports.generateVideo = async function (req, res) {
await createVideoFromImages([], options); await createVideoFromImages([], options);
filesCreated.push(path.dirname(videoPath)) 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);
!(async function () { !(async function () {
...@@ -117,24 +118,37 @@ module.exports.generateVideo = async function (req, res) { ...@@ -117,24 +118,37 @@ module.exports.generateVideo = async function (req, res) {
await createAudio(tutorShotData.audio, audioPath) await createAudio(tutorShotData.audio, audioPath)
finalVideoPath = path.join(TEMP_VIDEO_DIR, `ts-final-${tutorShotData._id}.mp4`); // path to combined video and audio finalVideoPath = path.join(TEMP_VIDEO_DIR, `ts-final-${tutorShotData._id}.mp4`); // path to combined video and audio
await joinAudioVideo(videoPath, audioPath, finalVideoPath) await joinAudioVideo(videoPath, audioPath, finalVideoPath)
}else{ } else {
socketPayload.percent = 100 socketPayload.percent = 99
socketPayload.subTask[0].percent = 100 socketPayload.subTask[0].percent = 99
socket.emit("videoGenerationProgress", socketPayload) socket.emit("videoGenerationProgress", socketPayload)
} }
} // uploading process
let remotePath = path.join(CONFIG.S3_TUTOR_SHOT, fileName) let remotePath = path.join(CONFIG.S3_TUTOR_SHOT, fileName)
let remoteThumbnailPath = path.join(CONFIG.S3_TUTOR_SHOT, thumbnailName) let remoteThumbnailPath = path.join(CONFIG.S3_TUTOR_SHOT, thumbnailName)
await uploadToAwsS3(videoPath, remotePath) await uploadToAwsS3(videoPath, remotePath)
await uploadToAwsS3(thumbnailPath, remoteThumbnailPath) await uploadToAwsS3(thumbnailPath, remoteThumbnailPath)
tutorShotData.thumbnailUrl = remoteThumbnailPath tutorShotData.thumbnailUrl = remoteThumbnailPath
tutorShotData.signedVideoUrl = await generatePreSignedGetUrl(remotePath)
tutorShotData.signedThumbnailUrl = await generatePreSignedGetUrl(remoteThumbnailPath)
tutorShotData.videoUrl = remotePath tutorShotData.videoUrl = remotePath
tutorShotData.generatingVideo = false tutorShotData.generatingVideo = false
console.log('----tutor-shot-generated----', tutorShotData?._id)
socketPayload.tutorShotData = {
videoUrl: remotePath,
thumbnailUrl: remoteThumbnailPath,
signedVideoUrl: tutorShotData?.signedVideoUrl,
signedThumbnailUrl: tutorShotData?.signedThumbnailUrl,
}
socketPayload.percent = 100
socketPayload.complete = true
socket.emit("videoGenerationProgress", socketPayload)
console.log('---Tutor-shot-generated----', tutorShotData?._id)
}
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)
......
...@@ -3,7 +3,6 @@ const socketIO = require('socket.io-client') ...@@ -3,7 +3,6 @@ const socketIO = require('socket.io-client')
const CONFIG = require('./config.js') const CONFIG = require('./config.js')
let socket = socketIO(CONFIG.SOCKET_URL) let socket = socketIO(CONFIG.SOCKET_URL)
socket.on('connect', ()=>{console.log('Socket connected!') }) socket.on('connect', ()=>{console.log('Socket connected!') })
socket.on('disconnect', ()=>{ console.log('Socket disconnected!') }) socket.on('disconnect', ()=>{ console.log('Socket disconnected!') })
......
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