37 lines
1.4 KiB
JavaScript
37 lines
1.4 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const { exec } = require('child_process');
|
|
|
|
const concatFilePath = path.join(__dirname, 'test_concat.txt');
|
|
const bgMusicPath = path.join(__dirname, '..', 'public', 'assets', 'audio', 'alegre.mp3');
|
|
const outputFilePath = path.join(__dirname, '..', 'public', 'generated-media', 'test_video.mp4');
|
|
|
|
const duration = 3;
|
|
const totalDuration = 6;
|
|
|
|
// Cria pasta generated-media se não existir
|
|
const mediaDir = path.dirname(outputFilePath);
|
|
if (!fs.existsSync(mediaDir)) {
|
|
fs.mkdirSync(mediaDir, { recursive: true });
|
|
}
|
|
|
|
// Usar camila_prof.png duas vezes
|
|
const testImg = path.join(__dirname, '..', 'public', 'assets', 'camila_prof.png');
|
|
|
|
let concatContent = `file '${testImg}'\nduration ${duration}\nfile '${testImg}'\nduration ${duration}\nfile '${testImg}'\n`;
|
|
fs.writeFileSync(concatFilePath, concatContent);
|
|
|
|
const ffmpegCommand = `ffmpeg -y -f concat -safe 0 -i "${concatFilePath}" -i "${bgMusicPath}" -c:v libx264 -pix_fmt yuv420p -c:a aac -shortest -t ${totalDuration} "${outputFilePath}"`;
|
|
console.log('Executando:', ffmpegCommand);
|
|
|
|
exec(ffmpegCommand, (error, stdout, stderr) => {
|
|
console.log('STDOUT:', stdout);
|
|
console.error('STDERR:', stderr);
|
|
if (error) {
|
|
console.error('Erro de execução:', error);
|
|
process.exit(1);
|
|
}
|
|
console.log('Vídeo gerado com sucesso em:', outputFilePath);
|
|
process.exit(0);
|
|
});
|