Commit 7ce04f32 by Pragati Upadhyay

issue fixed

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