Ajout de la fonction createVideo pour générer une vidéo à partir des images d'un projet, avec gestion des erreurs centralisée.

This commit is contained in:
2025-01-15 11:19:41 +01:00
parent 94fec8ac5f
commit 50b90bad39
2 changed files with 36 additions and 19 deletions

View File

@@ -7,6 +7,7 @@ const fs = require('fs');
const ffmpeg = require('../ffmpeg');
const fileUtils = require('../utils/fileUtils');
const serverError = require('../utils/serverError');
const video = require('../utils/video');
/**
* @swagger
@@ -50,29 +51,14 @@ router.get('/projects', async (req, res) => {
*/
router.get('/projects/:id/create-video', async (req, res) => {
const projectId = req.params.id;
const imageDir = `/storage/${projectId}`;
const outputVideo = `/storage/${projectId}/videos/output_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) {
return res.status(404).json({ 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}`;
require('child_process').execSync(ffmpegCommand);
fs.unlinkSync(tempFile);
res.status(200).json({ message: 'Video created successfully', videoPath: outputVideo });
const videoPath = await video.createVideo(projectId);
res.json(videoPath);
} catch (error) {
serverError.sendError('Error creating video:', res, error);
}
});
}
);
/**
* @swagger