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
8107f789
Commit
8107f789
authored
Mar 08, 2024
by
ramdayalmunda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
progress bar handling while generating video
parent
685ede17
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
26 deletions
+39
-26
tutor-shot.js
controller/tutor-shot.js
+39
-25
socket.js
socket.js
+0
-1
No files found.
controller/tutor-shot.js
View file @
8107f789
...
...
@@ -17,24 +17,25 @@ module.exports.generateVideo = async function (req, res) {
let
uid
;
let
_id
let
filesCreated
=
[]
let
socketPayload
try
{
let
tutorShotData
=
req
.
body
.
tutorShotData
;
let
videoPath
;
// local path of the video file
let
thumbnailPath
// local path of the thumbnail file
let
fileName
;
// remote name of the final video file
let
thumbnailName
;
// remote name of the final thumbnail
let
updatedData
;
if
(
tutorShotData
)
{
uid
=
tutorShotData
.
uid
_id
=
tutorShotData
.
_id
let
socketPayload
=
{
socketPayload
=
{
uid
:
tutorShotData
.
uid
,
_id
:
tutorShotData
.
_id
,
task
:
"Video Generation"
,
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
})
}
...
...
@@ -50,7 +51,7 @@ module.exports.generateVideo = async function (req, res) {
let
frameNumber
=
1
;
let
imageArr
=
[]
socket
.
emit
(
"videoGenerationProgress"
,
socketPayload
)
socket
.
emit
(
"videoGenerationProgress"
,
socketPayload
)
for
(
let
i
=
0
;
i
<
tutorShotData
.
segments
.
length
;
i
++
)
{
if
(
tutorShotData
.
segments
[
i
].
imageUrl
)
tutorShotData
.
segments
[
i
].
signedImageUrl
=
await
generatePreSignedGetUrl
(
tutorShotData
.
segments
[
i
].
imageUrl
)
...
...
@@ -83,9 +84,9 @@ module.exports.generateVideo = async function (req, res) {
filesCreated
.
push
(
thumbnailPath
)
}
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
);
socket
.
emit
(
"videoGenerationProgress"
,
socketPayload
);
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
);
socket
.
emit
(
"videoGenerationProgress"
,
socketPayload
);
}
...
...
@@ -101,8 +102,8 @@ module.exports.generateVideo = async function (req, res) {
await
createVideoFromImages
([],
options
);
filesCreated
.
push
(
path
.
dirname
(
videoPath
))
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
);
socket
.
emit
(
"videoGenerationProgress"
,
socketPayload
);
socketPayload
.
percent
=
Math
.
round
(
tutorShotData
?.
audio
?.
length
?
socketPayload
.
subTask
[
0
].
percent
/
2
:
socketPayload
.
subTask
[
0
].
percent
);
socket
.
emit
(
"videoGenerationProgress"
,
socketPayload
);
!
(
async
function
()
{
deleteFile
(
imageArr
)
...
...
@@ -112,29 +113,42 @@ module.exports.generateVideo = async function (req, res) {
if
(
tutorShotData
.
audio
?.
length
)
{
socketPayload
.
percent
=
50
socketPayload
.
subTask
[
0
].
percent
=
50
socket
.
emit
(
"videoGenerationProgress"
,
socketPayload
)
socket
.
emit
(
"videoGenerationProgress"
,
socketPayload
)
let
audioPath
=
path
.
join
(
TEMP_AUDIO_DIR
,
`ts-
${
tutorShotData
.
_id
}
.mp3`
);
// path to only audio
await
createAudio
(
tutorShotData
.
audio
,
audioPath
)
finalVideoPath
=
path
.
join
(
TEMP_VIDEO_DIR
,
`ts-final-
${
tutorShotData
.
_id
}
.mp4`
);
// path to combined video and audio
await
joinAudioVideo
(
videoPath
,
audioPath
,
finalVideoPath
)
}
else
{
socketPayload
.
percent
=
100
socketPayload
.
subTask
[
0
].
percent
=
100
socket
.
emit
(
"videoGenerationProgress"
,
socketPayload
)
}
else
{
socketPayload
.
percent
=
99
socketPayload
.
subTask
[
0
].
percent
=
99
socket
.
emit
(
"videoGenerationProgress"
,
socketPayload
)
}
}
// uploading process
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
.
signedVideoUrl
=
await
generatePreSignedGetUrl
(
remotePath
)
tutorShotData
.
signedThumbnailUrl
=
await
generatePreSignedGetUrl
(
remoteThumbnailPath
)
tutorShotData
.
videoUrl
=
remotePath
tutorShotData
.
generatingVideo
=
false
socketPayload
.
tutorShotData
=
{
videoUrl
:
remotePath
,
thumbnailUrl
:
remoteThumbnailPath
,
signedVideoUrl
:
tutorShotData
?.
signedVideoUrl
,
signedThumbnailUrl
:
tutorShotData
?.
signedThumbnailUrl
,
}
socketPayload
.
percent
=
100
socketPayload
.
complete
=
true
socket
.
emit
(
"videoGenerationProgress"
,
socketPayload
)
let
remotePath
=
path
.
join
(
CONFIG
.
S3_TUTOR_SHOT
,
fileName
)
let
remoteThumbnailPath
=
path
.
join
(
CONFIG
.
S3_TUTOR_SHOT
,
thumbnailName
)
console
.
log
(
'---Tutor-shot-generated----'
,
tutorShotData
?.
_id
)
}
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
)
...
...
socket.js
View file @
8107f789
...
...
@@ -3,7 +3,6 @@ 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!'
)
})
...
...
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