Commit 7ce04f32 by Pragati Upadhyay

issue fixed

parent 19deb370
...@@ -37,7 +37,6 @@ function createClipFromImage(imagePath, duration, outputClipPath, callback) { ...@@ -37,7 +37,6 @@ function createClipFromImage(imagePath, duration, outputClipPath, callback) {
]) ])
.output(outputClipPath) .output(outputClipPath)
.on('end', () => { .on('end', () => {
console.log(`Clip created: ${outputClipPath}`);
callback(null, outputClipPath); // Pass the clip path on success callback(null, outputClipPath); // Pass the clip path on success
}) })
.on('error', (err) => { .on('error', (err) => {
...@@ -71,37 +70,54 @@ function concatenateClips(clips, outputPath, callback) { ...@@ -71,37 +70,54 @@ function concatenateClips(clips, outputPath, callback) {
} }
module.exports.createVideo = async function(screenshots,outputPath) { module.exports.createVideo = async function (screenshots, outputPath) {
return new Promise(async (res, rej) => { return new Promise(async (resolve, reject) => {
let clips = []; const clips = [];
try {
for (let index = 0; index < screenshots.length; index++) {
const screenshot = screenshots[index];
const duration = screenshot.duration || 3;
const clipPath = `clip${index}.mp4`; // Temporary clip path
const clip = await createClipFromImageAsync(screenshot, duration, clipPath);
clips.push(clip);
}
console.log("🚀 ~ returnnewPromise ~ clips:", clips)
for (let index = 0; index < screenshots.length; index++) { await concatenateClipsAsync(clips, outputPath);
const screenshot = screenshots[index]; resolve();
const duration = screenshots[index]?.duration ? screenshots[index].duration : 3; } catch (error) {
const clipPath = `clip${index}.mp4`; // Temporary clip path console.error('Error processing video:', error);
reject(error);
}
});
};
// Helper function to convert callback-based createClipFromImage to promise-based
function createClipFromImageAsync(screenshot, duration, clipPath) {
return new Promise((resolve, reject) => {
createClipFromImage(screenshot, duration, clipPath, (err, clip) => { createClipFromImage(screenshot, duration, clipPath, (err, clip) => {
if (err) { if (err) {
console.error(`Failed to create clip for ${screenshot}: ${err}`); reject(err);
return; } else {
resolve(clip);
} }
});
});
}
clips.push(clip); // Helper function to convert callback-based concatenateClips to promise-based
function concatenateClipsAsync(clips, outputPath) {
if (index === screenshots.length - 1) { return new Promise((resolve, reject) => {
// All screenshots processed, concatenate clips concatenateClips(clips, outputPath, (err) => {
concatenateClips(clips, outputPath, (err) => { if (err) {
if (err) { reject(err);
console.error(`Failed to concatenate clips: ${err}`); } else {
return; resolve();
}
console.log('All done');
res();
});
} }
}); });
} });
});
} }
......
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