Commit 4160f708 by ramdayalmunda

jobs connected to socket

parent f56b21ab
......@@ -4,4 +4,5 @@ module.exports = {
S3_SECRET_KEY: process.env.S3_SECRET_KEY,
S3_BUCKET_NAME: process.env.S3_BUCKET_NAME,
S3_REGION: process.env.S3_REGION,
SOCKET_URL: process.env.SOCKET_URL,
}
\ No newline at end of file
......@@ -7,8 +7,9 @@ const { createVideoFromImages } = require("../helper/ffmpeg-helper")
const { deleteFile } = require("../helper/utilities")
const { generatePreSignedGetUrl } = require("../helper/upload")
const socket = require("../socket.js")
module.exports.generateVideo = async function (req, res) {
console.log('generate Video')
try {
let tutorShotData = req.body.tutorShotData;
......@@ -18,13 +19,11 @@ module.exports.generateVideo = async function (req, res) {
let thumbnailName; // remote name of the final thumbnail
if (tutorShotData) {
console.log('got tutor-shot Data')
let imageDir = TEMP_IMAGE_DIR
let imagePathString = path.join(imageDir, `${tutorShotData._id}_%d.png`)
videoPath = path.join(TEMP_VIDEO_DIR, `${tutorShotData._id}.mp4`)
console.log('videoPath', videoPath)
thumbnailPath = path.join(TEMP_IMAGE_DIR, `${tutorShotData._id}_thumbnail`)
fileName = tutorShotData._id
thumbnailName = `${tutorShotData._id}_thumbnail`
......@@ -33,9 +32,7 @@ module.exports.generateVideo = async function (req, res) {
let frameNumber = 1;
let imageArr = []
for (let i = 0; i < tutorShotData.segments.length; i++) {
console.log(i, 'tutor-shot', tutorShotData.segments[i])
if (tutorShotData.segments[i].imageUrl) tutorShotData.segments[i].signedImageUrl = await generatePreSignedGetUrl(tutorShotData.segments[i].imageUrl)
// if (tutorShotData.segments[i].thumbnailUrl) tutorShotData.segments[i].signedThumbnailUrl = await generatePreSignedGetUrl(tutorShotData.segments[i].thumbnailUrl)
let CE = generateCanvas(tutorShotData.segments[i], { dimension: tutorShotData.segments[i].dimension })
let mergedImage = await mergeImages(
[
......@@ -47,7 +44,6 @@ module.exports.generateVideo = async function (req, res) {
}
)
console.log('mergin image completed')
let limit = 24 * ((tutorShotData.segments[i]?.duration) ? (tutorShotData.segments[i].duration) : 2);
let frameNum = 0
let firstImage = path.join(imageDir, `${tutorShotData._id}_${frameNumber++}.png`)
......@@ -57,22 +53,16 @@ module.exports.generateVideo = async function (req, res) {
let fileName = path.join(imageDir, `${tutorShotData._id}_${frameNumber++}.png`)
imageArr.push(fileName)
fs.copyFileSync(firstImage, fileName)
console.log('image generated', fileName)
} while (++frameNum < limit)
if (i == 0 && thumbnailPath) {
fs.copyFileSync(firstImage, thumbnailPath)
console.log('thumbnail generated')
imageArr.push(thumbnailPath)
}
}
console.log('---ALL images generated', videoPath)
console.log('___BEFORE__')
console.log('outputFilePath', path.parse(videoPath))
console.log('outputFileName', path.dirname(videoPath).name)
console.log('__CONFIGURED___')
let options = {
outputFilePath: path.dirname(videoPath),
outputFileName: path.parse(videoPath).name,
......@@ -82,14 +72,17 @@ module.exports.generateVideo = async function (req, res) {
deleteImages: true,// default is true
}
console.log('to create Video from image')
await createVideoFromImages([], options)
console.log('Video from images Created')
// to delete the individual frames that were generated and the thumbnail
// !(async function () {
// deleteFile(imageArr)
// })()
// return videoPath
!(async function () {
deleteFile(imageArr)
})()
socket.emit("videoGenerationProgress", {
totalPercent: 100, // percentage of the overall task// video generation
percent: 100,
task: "Video Generation",
uid: tutorShotData.uid
})
}
......@@ -97,7 +90,6 @@ module.exports.generateVideo = async function (req, res) {
// let remoteThumbnailPath = path.join(CONFIG.S3_PATH.TUTOR_SHOT, thumbnailName)
// await uploadToAwsS3(videoPath, remotePath)
// await uploadToAwsS3(thumbnailPath, remoteThumbnailPath)
res.status(STATUS_CODE.OK).json()
} catch (err) {
console.log('------ERROR:GENERATING VIDEO',err)
......
......@@ -31,7 +31,6 @@ module.exports.mergeImages = async function (imageArr, options) {
compositeArr.push({ input: await nextSharp.toBuffer() })
}
imageSharp.composite(compositeArr)
await imageSharp.toFile('/var/www/BeGenieUs/begenieus-jobs/temporary/image/temp-1.png')
if (options.outputType == 'buffer') return imageSharp.toBuffer()
if (options.outputType == 'file' && options.outputFile) {
await imageSharp.toFile(options.outputFile)
......
......@@ -15,7 +15,8 @@
"express": "^4.18.3",
"fluent-ffmpeg": "^2.1.2",
"mongoose": "^8.2.1",
"sharp": "^0.32.1"
"sharp": "^0.32.1",
"socket.io-client": "^4.7.4"
}
},
"node_modules/@mapbox/node-pre-gyp": {
......@@ -45,6 +46,11 @@
"sparse-bitfield": "^3.0.3"
}
},
"node_modules/@socket.io/component-emitter": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz",
"integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg=="
},
"node_modules/@types/webidl-conversions": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz",
......@@ -551,6 +557,47 @@
"once": "^1.4.0"
}
},
"node_modules/engine.io-client": {
"version": "6.5.3",
"resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.5.3.tgz",
"integrity": "sha512-9Z0qLB0NIisTRt1DZ/8U2k12RJn8yls/nXMZLn+/N8hANT3TcYjKFKcwbw5zFQiN4NTde3TSY9zb79e1ij6j9Q==",
"dependencies": {
"@socket.io/component-emitter": "~3.1.0",
"debug": "~4.3.1",
"engine.io-parser": "~5.2.1",
"ws": "~8.11.0",
"xmlhttprequest-ssl": "~2.0.0"
}
},
"node_modules/engine.io-client/node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
"dependencies": {
"ms": "2.1.2"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/engine.io-client/node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/engine.io-parser": {
"version": "5.2.2",
"resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.2.tgz",
"integrity": "sha512-RcyUFKA93/CXH20l4SoVvzZfrSDMOTUS3bWVpTt2FuFP+XYrL8i8oonHP7WInRyVHXh0n/ORtoeiE1os+8qkSw==",
"engines": {
"node": ">=10.0.0"
}
},
"node_modules/es-define-property": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz",
......@@ -1988,6 +2035,74 @@
"is-arrayish": "^0.3.1"
}
},
"node_modules/socket.io-client": {
"version": "4.7.4",
"resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-4.7.4.tgz",
"integrity": "sha512-wh+OkeF0rAVCrABWQBaEjLfb7DVPotMbu0cgWgyR0v6eA4EoVnAwcIeIbcdTE3GT/H3kbdLl7OoH2+asoDRIIg==",
"dependencies": {
"@socket.io/component-emitter": "~3.1.0",
"debug": "~4.3.2",
"engine.io-client": "~6.5.2",
"socket.io-parser": "~4.2.4"
},
"engines": {
"node": ">=10.0.0"
}
},
"node_modules/socket.io-client/node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
"dependencies": {
"ms": "2.1.2"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/socket.io-client/node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/socket.io-parser": {
"version": "4.2.4",
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.4.tgz",
"integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==",
"dependencies": {
"@socket.io/component-emitter": "~3.1.0",
"debug": "~4.3.1"
},
"engines": {
"node": ">=10.0.0"
}
},
"node_modules/socket.io-parser/node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
"dependencies": {
"ms": "2.1.2"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/socket.io-parser/node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/sparse-bitfield": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz",
......@@ -2246,6 +2361,26 @@
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
},
"node_modules/ws": {
"version": "8.11.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz",
"integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": "^5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
},
"node_modules/xml2js": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.6.2.tgz",
......@@ -2266,6 +2401,14 @@
"node": ">=4.0"
}
},
"node_modules/xmlhttprequest-ssl": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-2.0.0.tgz",
"integrity": "sha512-QKxVRxiRACQcVuQEYFsI1hhkrMlrXHPegbbd1yn9UHOmRxY+si12nQYzri3vbzt8VdTTRviqcKxcyllFas5z2A==",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
......
......@@ -17,6 +17,7 @@
"express": "^4.18.3",
"fluent-ffmpeg": "^2.1.2",
"mongoose": "^8.2.1",
"sharp": "^0.32.1"
"sharp": "^0.32.1",
"socket.io-client": "^4.7.4"
}
}
const socketIO = require('socket.io-client')
const CONFIG = require('./config.js')
let socket = socketIO(CONFIG.SOCKET_URL)
socket.on('connect', ()=>{console.log('Socket connected!') })
socket.on('disconnect', ()=>{ console.log('Socket disconnected!') })
module.exports = socket
\ No newline at end of file
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