Ajouter la prise en charge de la résolution personnalisée lors de la création de vidéos
This commit is contained in:
@@ -57,9 +57,15 @@ router.post('/videos', async (req, res) => {
|
|||||||
|
|
||||||
const { duration: videoDuration, measurement_ids: videoMeasurementIds, project_id: videoProjectId } = result.rows[0];
|
const { duration: videoDuration, measurement_ids: videoMeasurementIds, project_id: videoProjectId } = result.rows[0];
|
||||||
const pathList = await measureManager.getPathList(videoMeasurementIds, videoProjectId);
|
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
|
// Start background processing
|
||||||
videoManager.createVideoWithList(videoProjectId, pathList, videoDuration, videoId)
|
videoManager.createVideoWithList(videoProjectId, pathList, videoDuration, videoId, res_width, res_height)
|
||||||
.then(videoFile => {
|
.then(videoFile => {
|
||||||
console.log('Rendu vidéo terminé:', videoFile);
|
console.log('Rendu vidéo terminé:', videoFile);
|
||||||
return videoManager.updateVideoFile(videoId, videoFile);
|
return videoManager.updateVideoFile(videoId, videoFile);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ async function deleteVideoProject(videoId) {
|
|||||||
return res.rows[0];
|
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');
|
const tempFile = path.join('temp.txt');
|
||||||
let ffmpegProcess;
|
let ffmpegProcess;
|
||||||
let cleanupDone = false;
|
let cleanupDone = false;
|
||||||
@@ -76,6 +76,7 @@ async function createVideoWithList(projectId, pathList, duration, videoId) {
|
|||||||
eta = NULL
|
eta = NULL
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`, [videoId]);
|
`, [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
|
// Configuration de FFmpeg
|
||||||
const ffmpegArgs = [
|
const ffmpegArgs = [
|
||||||
@@ -86,7 +87,7 @@ async function createVideoWithList(projectId, pathList, duration, videoId) {
|
|||||||
'-i', tempFile,
|
'-i', tempFile,
|
||||||
'-vsync', 'vfr',
|
'-vsync', 'vfr',
|
||||||
'-pix_fmt', 'yuv420p',
|
'-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)
|
'-b:v', '1500k', // Force un bitrate vidéo de 1500 kbps (ajuste si nécessaire)
|
||||||
outputVideo
|
outputVideo
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user