up
This commit is contained in:
+26
-1
@@ -82,7 +82,32 @@ try {
|
||||
if (!move_uploaded_file($fileTmpPath, $uploadPath)) {
|
||||
throw new Exception('Error al guardar el archivo en el servidor');
|
||||
}
|
||||
|
||||
|
||||
// Si es audio WebM, intentar convertir a OGG/Opus (formatos más compatibles con WhatsApp)
|
||||
if (strpos($fileType, 'audio/webm') === 0) {
|
||||
$ffmpeg = trim(@shell_exec('which ffmpeg 2>/dev/null'));
|
||||
if ($ffmpeg) {
|
||||
$convertedName = uniqid('media_', true) . '.ogg';
|
||||
$convertedPath = $uploadDir . $convertedName;
|
||||
// Convertir a Opus (bitrate moderado)
|
||||
$cmd = escapeshellcmd($ffmpeg) . ' -y -i ' . escapeshellarg($uploadPath) . ' -c:a libopus -b:a 64000 ' . escapeshellarg($convertedPath) . ' 2>&1';
|
||||
$out = shell_exec($cmd);
|
||||
if (file_exists($convertedPath) && filesize($convertedPath) > 0) {
|
||||
// Reemplazar archivo original por el convertido
|
||||
@unlink($uploadPath);
|
||||
$uploadPath = $convertedPath;
|
||||
$uniqueName = $convertedName;
|
||||
$fileType = 'audio/ogg';
|
||||
error_log('upload_media.php - Audio convertido a OGG/Opus: ' . $convertedName);
|
||||
error_log('upload_media.php - ffmpeg output: ' . substr($out, 0, 2000));
|
||||
} else {
|
||||
error_log('upload_media.php - Falló conversión con ffmpeg. Output: ' . substr($out, 0, 2000));
|
||||
}
|
||||
} else {
|
||||
error_log('upload_media.php - ffmpeg no encontrado, no se puede convertir audio/webm.');
|
||||
}
|
||||
}
|
||||
|
||||
// Construir URL pública
|
||||
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
|
||||
Reference in New Issue
Block a user