const sharp = require('sharp'); const { exec } = require('child_process'); function createVideoThumbnail(videoPath, thumbMinPath, thumbAvgPath) { return new Promise((resolve) => { const cmd = ` ffmpeg -y -i "${videoPath}" -ss 00:00:01.000 -vframes 1 "${thumbAvgPath}" && ffmpeg -y -i "${thumbAvgPath}" -vf "scale=100:-1" "${thumbMinPath}" `; exec(cmd, () => resolve()); }); } async function createThumbnails(filePath, thumbMinPath, thumbAvgPath) { try { await sharp(filePath) .resize({ width: 100, height: 100, fit: 'inside', withoutEnlargement: true }) .withMetadata() .toFile(thumbMinPath); await sharp(filePath) .resize({ width: 400, withoutEnlargement: true }) .withMetadata() .toFile(thumbAvgPath); } catch (err) { console.error('Errore creazione thumbnails:', err.message, filePath); } } module.exports = { createVideoThumbnail, createThumbnails };