From 9101497a7f55827ef9a4fdceaded2b19ca74623b Mon Sep 17 00:00:00 2001 From: Kerboul Date: Mon, 31 Mar 2025 11:22:19 +0200 Subject: [PATCH] =?UTF-8?q?Ajouter=20la=20prise=20en=20charge=20de=20la=20?= =?UTF-8?q?r=C3=A9solution=20personnalis=C3=A9e=20lors=20de=20la=20cr?= =?UTF-8?q?=C3=A9ation=20de=20vid=C3=A9os?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/videoRoutes.js | 8 +++++++- src/video/videoManager.js | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/routes/videoRoutes.js b/routes/videoRoutes.js index 46c7486..d909650 100644 --- a/routes/videoRoutes.js +++ b/routes/videoRoutes.js @@ -57,9 +57,15 @@ router.post('/videos', async (req, res) => { const { duration: videoDuration, measurement_ids: videoMeasurementIds, project_id: videoProjectId } = result.rows[0]; const pathList = await measureManager.getPathList(videoMeasurementIds, videoProjectId); + + // parser la résolution (ex: 1920x1080) + const [res_width, res_height] = resolution.split('x').map(Number); + if (isNaN(res_width) || isNaN(res_height)) { + return res.status(400).json({ error: 'Invalid resolution format. Use WIDTHxHEIGHT (e.g., 1920x1080)' }); + } // Start background processing - videoManager.createVideoWithList(videoProjectId, pathList, videoDuration, videoId) + videoManager.createVideoWithList(videoProjectId, pathList, videoDuration, videoId, res_width, res_height) .then(videoFile => { console.log('Rendu vidéo terminé:', videoFile); return videoManager.updateVideoFile(videoId, videoFile); diff --git a/src/video/videoManager.js b/src/video/videoManager.js index 874e1b9..eefb1e9 100644 --- a/src/video/videoManager.js +++ b/src/video/videoManager.js @@ -32,7 +32,7 @@ async function deleteVideoProject(videoId) { return res.rows[0]; } -async function createVideoWithList(projectId, pathList, duration, videoId) { +async function createVideoWithList(projectId, pathList, duration, videoId, res_width, res_height) { const tempFile = path.join('temp.txt'); let ffmpegProcess; let cleanupDone = false; @@ -76,6 +76,7 @@ async function createVideoWithList(projectId, pathList, duration, videoId) { eta = NULL WHERE id = $1 `, [videoId]); + const scale = res_width && res_height ? `scale=${res_width}:${res_height}` : 'scale=854:480'; // Redimensionne la vidéo en 480p par défaut // Configuration de FFmpeg const ffmpegArgs = [ @@ -86,7 +87,7 @@ async function createVideoWithList(projectId, pathList, duration, videoId) { '-i', tempFile, '-vsync', 'vfr', '-pix_fmt', 'yuv420p', - '-vf', 'scale=854:480', // Redimensionne la vidéo en 480p + '-vf', scale, '-b:v', '1500k', // Force un bitrate vidéo de 1500 kbps (ajuste si nécessaire) outputVideo ];