Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
begenieus-jobs
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ramdayal Munda
begenieus-jobs
Commits
ffbb5539
Commit
ffbb5539
authored
Mar 07, 2024
by
ramdayalmunda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sending data back to server
parent
b237c5ad
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
34 deletions
+14
-34
config.js
config.js
+2
-0
tutor-shot.js
controller/tutor-shot.js
+12
-22
ffmpeg-helper.js
helper/ffmpeg-helper.js
+0
-12
No files found.
config.js
View file @
ffbb5539
...
@@ -5,4 +5,5 @@ module.exports = {
...
@@ -5,4 +5,5 @@ module.exports = {
S3_BUCKET_NAME
:
process
.
env
.
S3_BUCKET_NAME
,
S3_BUCKET_NAME
:
process
.
env
.
S3_BUCKET_NAME
,
S3_REGION
:
process
.
env
.
S3_REGION
,
S3_REGION
:
process
.
env
.
S3_REGION
,
SOCKET_URL
:
process
.
env
.
SOCKET_URL
,
SOCKET_URL
:
process
.
env
.
SOCKET_URL
,
S3_TUTOR_SHOT
:
process
.
env
.
S3_TUTOR_SHOT
,
}
}
\ No newline at end of file
controller/tutor-shot.js
View file @
ffbb5539
...
@@ -5,17 +5,16 @@ const sharp = require('sharp')
...
@@ -5,17 +5,16 @@ const sharp = require('sharp')
const
fs
=
require
(
'fs'
)
const
fs
=
require
(
'fs'
)
const
{
createVideoFromImages
,
joinAudioVideo
}
=
require
(
"../helper/ffmpeg-helper"
)
const
{
createVideoFromImages
,
joinAudioVideo
}
=
require
(
"../helper/ffmpeg-helper"
)
const
{
deleteFile
,
downloadFile
}
=
require
(
"../helper/utilities"
)
const
{
deleteFile
,
downloadFile
}
=
require
(
"../helper/utilities"
)
const
{
generatePreSignedGetUrl
}
=
require
(
"../helper/upload"
)
const
{
generatePreSignedGetUrl
,
uploadToAwsS3
}
=
require
(
"../helper/upload"
)
const
mongoose
=
require
(
'mongoose'
)
const
mongoose
=
require
(
'mongoose'
)
const
ObjectId
=
mongoose
.
Types
.
ObjectId
const
ObjectId
=
mongoose
.
Types
.
ObjectId
const
ffmpeg
=
require
(
"fluent-ffmpeg"
);
const
ffmpeg
=
require
(
"fluent-ffmpeg"
);
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
)
{
console
.
log
(
'generateVideo'
)
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
...
@@ -33,7 +32,6 @@ module.exports.generateVideo = async function (req, res) {
...
@@ -33,7 +32,6 @@ module.exports.generateVideo = async function (req, res) {
if
(
tutorShotData
?.
audio
?.
length
){
if
(
tutorShotData
?.
audio
?.
length
){
socketPayload
.
subTask
.
push
({
task
:
"Audio mixing"
,
percent
:
0
})
socketPayload
.
subTask
.
push
({
task
:
"Audio mixing"
,
percent
:
0
})
}
}
console
.
log
(
'data to generate found'
)
let
imageDir
=
TEMP_IMAGE_DIR
let
imageDir
=
TEMP_IMAGE_DIR
let
imagePathString
=
path
.
join
(
imageDir
,
`
${
tutorShotData
.
_id
}
_%d.png`
)
let
imagePathString
=
path
.
join
(
imageDir
,
`
${
tutorShotData
.
_id
}
_%d.png`
)
...
@@ -75,7 +73,6 @@ module.exports.generateVideo = async function (req, res) {
...
@@ -75,7 +73,6 @@ module.exports.generateVideo = async function (req, res) {
if
(
i
==
0
&&
thumbnailPath
)
{
if
(
i
==
0
&&
thumbnailPath
)
{
fs
.
copyFileSync
(
firstImage
,
thumbnailPath
)
fs
.
copyFileSync
(
firstImage
,
thumbnailPath
)
imageArr
.
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
...
@@ -102,37 +99,33 @@ module.exports.generateVideo = async function (req, res) {
...
@@ -102,37 +99,33 @@ module.exports.generateVideo = async function (req, res) {
deleteFile
(
imageArr
)
deleteFile
(
imageArr
)
})()
})()
console
.
log
(
'------VIDEO GENERATED------'
)
// // to save audio
// // to save audio
if
(
tutorShotData
.
audio
?.
length
)
{
if
(
tutorShotData
.
audio
?.
length
)
{
socketPayload
.
percent
=
50
socketPayload
.
percent
=
50
socketPayload
.
subTask
[
0
].
percent
=
50
socketPayload
.
subTask
[
0
].
percent
=
50
socket
.
emit
(
"videoGenerationProgress"
,
socketPayload
)
socket
.
emit
(
"videoGenerationProgress"
,
socketPayload
)
console
.
log
(
'to generate audio'
)
let
audioPath
=
path
.
join
(
TEMP_AUDIO_DIR
,
`ts-
${
tutorShotData
.
_id
}
.mp3`
);
// path to only 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
)
await
createAudio
(
tutorShotData
.
audio
,
audioPath
)
console
.
log
(
'Audio created'
)
finalVideoPath
=
path
.
join
(
TEMP_VIDEO_DIR
,
`ts-final-
${
tutorShotData
.
_id
}
.mp4`
);
// path to combined video and audio
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'
)
await
joinAudioVideo
(
videoPath
,
audioPath
,
finalVideoPath
)
await
joinAudioVideo
(
videoPath
,
audioPath
,
finalVideoPath
)
console
.
log
(
'---AUDIO VIDEO JOINED----'
)
}
else
{
}
else
{
socketPayload
.
percent
=
100
socketPayload
.
percent
=
100
socketPayload
.
subTask
[
0
].
percent
=
100
socketPayload
.
subTask
[
0
].
percent
=
100
socket
.
emit
(
"videoGenerationProgress"
,
socketPayload
)
socket
.
emit
(
"videoGenerationProgress"
,
socketPayload
)
}
}
console
.
log
(
'got updated data'
,
updatedData
)
}
}
// let remotePath = path.join(CONFIG.S3_PATH.TUTOR_SHOT, fileName)
let
remotePath
=
path
.
join
(
CONFIG
.
S3_TUTOR_SHOT
,
fileName
)
// let remoteThumbnailPath = path.join(CONFIG.S3_PATH.TUTOR_SHOT, thumbnailName)
let
remoteThumbnailPath
=
path
.
join
(
CONFIG
.
S3_TUTOR_SHOT
,
thumbnailName
)
// await uploadToAwsS3(videoPath, remotePath)
// await uploadToAwsS3(thumbnailPath, remoteThumbnailPath)
await
uploadToAwsS3
(
videoPath
,
remotePath
)
console
.
log
(
'------SENDING RESPONSE-------'
)
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
)
res
.
status
(
STATUS_CODE
.
OK
).
json
(
tutorShotData
)
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
'------ERROR:GENERATING VIDEO'
,
err
)
console
.
log
(
'------ERROR:GENERATING VIDEO'
,
err
)
...
@@ -181,7 +174,6 @@ async function createAudio(audioList, audioPath) {
...
@@ -181,7 +174,6 @@ async function createAudio(audioList, audioPath) {
}
}
await
Promise
.
all
(
downloadAudioPromise
)
await
Promise
.
all
(
downloadAudioPromise
)
console
.
log
(
'AUDIO files Created'
)
await
new
Promise
((
res
,
rej
)
=>
{
await
new
Promise
((
res
,
rej
)
=>
{
...
@@ -208,7 +200,6 @@ async function createAudio(audioList, audioPath) {
...
@@ -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`
let
command
=
`ffmpeg -f lavfi -i anullsrc=r=44100 -t
${
waitTime
}
-c:a libmp3lame -q:a 0
${
silenceAudio
}
-y`
execSync
(
command
)
execSync
(
command
)
console
.
log
(
a
,
'Mute audio created'
)
audioObj
.
input
(
silenceAudio
).
inputOptions
(
'-ss'
,
'0'
);
audioObj
.
input
(
silenceAudio
).
inputOptions
(
'-ss'
,
'0'
);
tempFiles
.
push
(
silenceAudio
)
tempFiles
.
push
(
silenceAudio
)
}
}
...
@@ -216,7 +207,6 @@ async function createAudio(audioList, audioPath) {
...
@@ -216,7 +207,6 @@ async function createAudio(audioList, audioPath) {
}
}
audioObj
.
mergeToFile
(
audioPath
,
path
.
dirname
(
audioPath
))
audioObj
.
mergeToFile
(
audioPath
,
path
.
dirname
(
audioPath
))
console
.
log
(
'audio merged'
)
})
})
return
return
...
...
helper/ffmpeg-helper.js
View file @
ffbb5539
...
@@ -27,9 +27,6 @@ const path = require('path')
...
@@ -27,9 +27,6 @@ const path = require('path')
module
.
exports
.
createVideoFromImages
=
async
function
(
imageArr
,
options
)
{
module
.
exports
.
createVideoFromImages
=
async
function
(
imageArr
,
options
)
{
return
new
Promise
(
async
(
res
,
rej
)
=>
{
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
frameRate
=
options
?.
frameRate
?
options
.
frameRate
:
24
let
tempImageDir
=
path
.
join
(
__dirname
,
'..'
,
'temporary'
,
'images'
)
let
tempImageDir
=
path
.
join
(
__dirname
,
'..'
,
'temporary'
,
'images'
)
...
@@ -44,7 +41,6 @@ module.exports.createVideoFromImages = async function (imageArr, options) {
...
@@ -44,7 +41,6 @@ module.exports.createVideoFromImages = async function (imageArr, options) {
imagePathString
=
path
.
join
(
tempImageDir
,
`
${
options
.
outputFileName
}
_%d.png`
)
imagePathString
=
path
.
join
(
tempImageDir
,
`
${
options
.
outputFileName
}
_%d.png`
)
////// to create temporary image files //////
////// to create temporary image files //////
for
(
let
i
=
0
;
i
<
imageArr
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
imageArr
.
length
;
i
++
)
{
console
.
log
(
'looping image arr'
)
if
(
imageArr
[
i
].
filePath
)
{
if
(
imageArr
[
i
].
filePath
)
{
let
limit
=
imageArr
[
i
]?.
duration
?
imageArr
[
i
].
duration
:
1
let
limit
=
imageArr
[
i
]?.
duration
?
imageArr
[
i
].
duration
:
1
limit
=
limit
*
frameRate
limit
=
limit
*
frameRate
...
@@ -60,13 +56,8 @@ module.exports.createVideoFromImages = async function (imageArr, options) {
...
@@ -60,13 +56,8 @@ module.exports.createVideoFromImages = async function (imageArr, options) {
}
}
////// using ffmpeg creating video //////
////// using ffmpeg creating video //////
console
.
log
(
'ffmpeg config'
)
console
.
log
(
'imagePathString'
,
imagePathString
)
console
.
log
(
'outputFilePath'
,
outputFilePath
)
console
.
log
(
'frameRate'
,
frameRate
)
ffmpeg
()
ffmpeg
()
.
on
(
'end'
,
()
=>
{
.
on
(
'end'
,
()
=>
{
console
.
log
(
'VIDEO END'
)
res
(
path
.
join
(
options
.
outputFilePath
,
`
${
options
.
outputFileName
}
.
${
options
.
outputFormat
}
`
))
res
(
path
.
join
(
options
.
outputFilePath
,
`
${
options
.
outputFileName
}
.
${
options
.
outputFormat
}
`
))
////// to delete the frames that are created //////
////// to delete the frames that are created //////
...
@@ -98,9 +89,6 @@ module.exports.createVideoFromImages = async function (imageArr, options) {
...
@@ -98,9 +89,6 @@ module.exports.createVideoFromImages = async function (imageArr, options) {
module
.
exports
.
joinAudioVideo
=
async
function
(
videoPath
,
audioPath
,
output
)
{
module
.
exports
.
joinAudioVideo
=
async
function
(
videoPath
,
audioPath
,
output
)
{
return
new
Promise
((
res
,
rej
)
=>
{
return
new
Promise
((
res
,
rej
)
=>
{
console
.
log
(
'videoPath'
,
videoPath
)
console
.
log
(
'audioPath'
,
audioPath
)
console
.
log
(
'output'
,
output
)
ffmpeg
()
ffmpeg
()
.
on
(
'end'
,
()
=>
{
.
on
(
'end'
,
()
=>
{
res
(
output
)
res
(
output
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment