chore: melhora mensagem de erro do FFmpeg pós reinicialização do container
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
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);
|
||||
});
|
||||
@@ -504,7 +504,7 @@ app.post('/api/comics/generate-video', requireAuth, async (req, res) => {
|
||||
|
||||
if (error) {
|
||||
console.error('Erro ao processar FFmpeg:', error, stderr);
|
||||
return res.status(500).json({ error: 'Erro ao gerar o vídeo da apresentação.' });
|
||||
return res.status(500).json({ error: 'Erro ao gerar o vídeo da apresentação. Como o servidor foi atualizado e reiniciado recentemente, por favor crie/gere a história em quadrinhos novamente para recriar as imagens temporárias antes de exportar o vídeo.' });
|
||||
}
|
||||
|
||||
res.json({ videoUrl: `/generated-media/${outputFileName}` });
|
||||
|
||||
Reference in New Issue
Block a user