Migration de la fonction de création de vidéo vers un nouveau module et suppression de l'ancienne implémentation

This commit is contained in:
2025-02-11 19:26:42 +01:00
parent 66d51f24d9
commit f56c35c5f9
5 changed files with 56 additions and 32 deletions

View File

@@ -1,31 +0,0 @@
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const serverError = require('../utils/serverError');
async function createVideo(projectId) {
const imageDir = `/storage/${projectId}`;
const outputVideo = `/storage/videos/output_${projectId}_video.mp4`;
const frameRate = 24;
const tempFile = `/storage/${projectId}/temp_file.txt`;
try {
const images = fs.readdirSync(imageDir).filter(file => file.endsWith('.jpg'));
if (images.length === 0) {
throw new Error('No images found for this project');
}
const tempFileContent = images.map(img => `file '${path.join(imageDir, img)}'`).join('\n');
fs.writeFileSync(tempFile, tempFileContent);
const ffmpegCommand = `ffmpeg -r ${frameRate} -f concat -safe 0 -i ${tempFile} -vsync vfr -pix_fmt yuv420p ${outputVideo}`;
execSync(ffmpegCommand);
fs.unlinkSync(tempFile);
return { message: 'Video created successfully', videoPath: outputVideo };
} catch (error) {
throw new Error(`Error creating video: ${error.message}`);
}
}
module.exports = { createVideo };