Tri des images numériquement avant la création de la vidéo et mise à jour du fichier temporaire
This commit is contained in:
@@ -9,16 +9,22 @@ const PROJECTS_DIR = path.join('.');
|
||||
async function createVideo(projectId) {
|
||||
const tempFile = path.join('temp.txt');
|
||||
try {
|
||||
// trouver tous les fichiers image pour le projet donné
|
||||
// Trouver tous les fichiers image pour le projet donné
|
||||
const workdir = path.join(PROJECTS_DIR, 'storage', `${projectId}`);
|
||||
const dir = path.join(PROJECTS_DIR, 'storage', `${projectId}`, 'images');
|
||||
console.log('dir:', dir);
|
||||
const images = storageManager.scanAllImages(dir);
|
||||
console.log('images:', images);
|
||||
|
||||
// Trier les images numériquement
|
||||
const sortedImages = images.sort((a, b) => {
|
||||
const numA = parseInt(path.basename(a).match(/\d+/)[0], 10);
|
||||
const numB = parseInt(path.basename(b).match(/\d+/)[0], 10);
|
||||
return numA - numB;
|
||||
});
|
||||
|
||||
// Créer un fichier temporaire pour la liste des images
|
||||
const tempFile = path.join('temp.txt');
|
||||
fs.writeFileSync(tempFile, images.map(image => `file '${image}'`).join('\n'));
|
||||
fs.writeFileSync(tempFile, sortedImages.map(image => `file '${image}'`).join('\n'));
|
||||
|
||||
const frameRate = 10;
|
||||
const outputVideo = path.join(workdir, 'video.mp4');
|
||||
@@ -39,8 +45,5 @@ async function createVideo(projectId) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Commande ffmpeg pour créer la vidéo
|
||||
//const ffmpegCommand = `ffmpeg -r ${frameRate} -f concat -safe 0 -i ${tempFile} -vsync vfr -pix_fmt yuv420p ${outputVideo}`;
|
||||
//execSync(ffmpegCommand);
|
||||
|
||||
module.exports = { createVideo };
|
||||
|
||||
Reference in New Issue
Block a user