Commit ffbb5539 by ramdayalmunda

sending data back to server

parent b237c5ad
......@@ -5,4 +5,5 @@ module.exports = {
S3_BUCKET_NAME: process.env.S3_BUCKET_NAME,
S3_REGION: process.env.S3_REGION,
SOCKET_URL: process.env.SOCKET_URL,
S3_TUTOR_SHOT: process.env.S3_TUTOR_SHOT,
}
\ No newline at end of file
......@@ -5,17 +5,16 @@ const sharp = require('sharp')
const fs = require('fs')
const { createVideoFromImages, joinAudioVideo } = require("../helper/ffmpeg-helper")
const { deleteFile, downloadFile } = require("../helper/utilities")
const { generatePreSignedGetUrl } = require("../helper/upload")
const { generatePreSignedGetUrl, uploadToAwsS3 } = require("../helper/upload")
const mongoose = require('mongoose')
const ObjectId = mongoose.Types.ObjectId
const ffmpeg = require("fluent-ffmpeg");
const CONFIG = require("../config.js")
const socket = require("../socket.js")
module.exports.generateVideo = async function (req, res) {
console.log('generateVideo')
try {
let tutorShotData = req.body.tutorShotData;
let videoPath; // local path of the video file
......@@ -33,7 +32,6 @@ module.exports.generateVideo = async function (req, res) {
if ( tutorShotData?.audio?.length ){
socketPayload.subTask.push({ task: "Audio mixing", percent: 0 })
}
console.log('data to generate found')
let imageDir = TEMP_IMAGE_DIR
let imagePathString = path.join(imageDir, `${tutorShotData._id}_%d.png`)
......@@ -75,7 +73,6 @@ module.exports.generateVideo = async function (req, res) {
if (i == 0 && thumbnailPath) {
fs.copyFileSync(firstImage, thumbnailPath)
imageArr.push(thumbnailPath)
}
socketPayload.subTask[0].percent = Math.round(((i+1)/tutorShotData.segments.length)*75); // 75% for generating images
......@@ -102,37 +99,33 @@ module.exports.generateVideo = async function (req, res) {
deleteFile(imageArr)
})()
console.log('------VIDEO GENERATED------')
// // to save audio
if (tutorShotData.audio?.length) {
socketPayload.percent = 50
socketPayload.subTask[0].percent = 50
socket.emit("videoGenerationProgress", socketPayload)
console.log('to generate audio')
let audioPath = path.join(TEMP_AUDIO_DIR, `ts-${tutorShotData._id}.mp3`); // path to only audio
console.log('audioPath', audioPath)
await createAudio(tutorShotData.audio, audioPath)
console.log('Audio created')
finalVideoPath = path.join(CONFIG.DEFAULT_PATH.TEMP_VIDEO, `ts-final-${tutorShotData._id}.mp4`); // path to combined video and audio
console.log('joining Audio and video')
finalVideoPath = path.join(TEMP_VIDEO_DIR, `ts-final-${tutorShotData._id}.mp4`); // path to combined video and audio
await joinAudioVideo(videoPath, audioPath, finalVideoPath)
console.log('---AUDIO VIDEO JOINED----')
}else{
socketPayload.percent = 100
socketPayload.subTask[0].percent = 100
socket.emit("videoGenerationProgress", socketPayload)
}
console.log('got updated data', updatedData)
}
// let remotePath = path.join(CONFIG.S3_PATH.TUTOR_SHOT, fileName)
// let remoteThumbnailPath = path.join(CONFIG.S3_PATH.TUTOR_SHOT, thumbnailName)
// await uploadToAwsS3(videoPath, remotePath)
// await uploadToAwsS3(thumbnailPath, remoteThumbnailPath)
console.log('------SENDING RESPONSE-------')
let remotePath = path.join(CONFIG.S3_TUTOR_SHOT, fileName)
let remoteThumbnailPath = path.join(CONFIG.S3_TUTOR_SHOT, thumbnailName)
await uploadToAwsS3(videoPath, remotePath)
await uploadToAwsS3(thumbnailPath, remoteThumbnailPath)
tutorShotData.thumbnailUrl = remoteThumbnailPath
tutorShotData.videoUrl = remotePath
tutorShotData.generatingVideo = false
console.log('----tutor-shot-generated----', tutorShotData?._id)
res.status(STATUS_CODE.OK).json(tutorShotData)
} catch (err) {
console.log('------ERROR:GENERATING VIDEO', err)
......@@ -181,7 +174,6 @@ async function createAudio(audioList, audioPath) {
}
await Promise.all(downloadAudioPromise)
console.log('AUDIO files Created')
await new Promise((res, rej) => {
......@@ -208,7 +200,6 @@ async function createAudio(audioList, audioPath) {
}
let command = `ffmpeg -f lavfi -i anullsrc=r=44100 -t ${waitTime} -c:a libmp3lame -q:a 0 ${silenceAudio} -y`
execSync(command)
console.log(a, 'Mute audio created')
audioObj.input(silenceAudio).inputOptions('-ss', '0');
tempFiles.push(silenceAudio)
}
......@@ -216,7 +207,6 @@ async function createAudio(audioList, audioPath) {
}
audioObj.mergeToFile(audioPath, path.dirname(audioPath))
console.log('audio merged')
})
return
......
......@@ -27,9 +27,6 @@ const path = require('path')
module.exports.createVideoFromImages = async function (imageArr, options) {
return new Promise(async (res, rej) => {
console.log('createVideoFromImages')
console.log('imageArr', imageArr)
console.log('options', options)
let frameRate = options?.frameRate ? options.frameRate : 24
let tempImageDir = path.join(__dirname, '..', 'temporary', 'images')
......@@ -44,7 +41,6 @@ module.exports.createVideoFromImages = async function (imageArr, options) {
imagePathString = path.join(tempImageDir, `${options.outputFileName}_%d.png`)
////// to create temporary image files //////
for (let i = 0; i < imageArr.length; i++) {
console.log('looping image arr')
if (imageArr[i].filePath) {
let limit = imageArr[i]?.duration ? imageArr[i].duration : 1
limit = limit * frameRate
......@@ -60,13 +56,8 @@ module.exports.createVideoFromImages = async function (imageArr, options) {
}
////// using ffmpeg creating video //////
console.log('ffmpeg config')
console.log('imagePathString', imagePathString)
console.log('outputFilePath', outputFilePath)
console.log('frameRate', frameRate)
ffmpeg()
.on('end', () => {
console.log('VIDEO END')
res(path.join(options.outputFilePath, `${options.outputFileName}.${options.outputFormat}`))
////// to delete the frames that are created //////
......@@ -98,9 +89,6 @@ module.exports.createVideoFromImages = async function (imageArr, options) {
module.exports.joinAudioVideo = async function (videoPath, audioPath, output) {
return new Promise((res, rej) => {
console.log('videoPath', videoPath)
console.log('audioPath', audioPath)
console.log('output', output)
ffmpeg()
.on('end', () => {
res(output)
......
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