query(" SELECT id, title, video_url, video_platform, video_converted FROM lessons WHERE type = 'video' AND video_platform = 'local' AND video_url IS NOT NULL AND deleted_at IS NULL ORDER BY created_at DESC "); $videos = $stmt->fetchAll(); // Verifica se FFmpeg è disponibile function check_ffmpeg() { $output = []; $return_var = 0; exec('ffmpeg -version 2>&1', $output, $return_var); return $return_var === 0; } $ffmpeg_available = check_ffmpeg(); // Funzione per convertire un video function convert_video($input_path, $output_path) { $command = sprintf( 'ffmpeg -i %s -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 128k -movflags +faststart -y %s 2>&1', escapeshellarg($input_path), escapeshellarg($output_path) ); $output = []; $return_var = 0; exec($command, $output, $return_var); return [ 'success' => $return_var === 0, 'output' => implode("\n", $output) ]; } // Processa conversione se richiesta if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['convert_video'])) { $lesson_id = intval($_POST['lesson_id'] ?? 0); if ($lesson_id > 0) { $stmt = $pdo->prepare("SELECT video_url FROM lessons WHERE id = ?"); $stmt->execute([$lesson_id]); $lesson = $stmt->fetch(); if ($lesson && $lesson['video_url']) { $video_path = ltrim($lesson['video_url'], '/'); $input_file = __DIR__ . '/' . $video_path; if (file_exists($input_file)) { // Crea nome file di output $path_info = pathinfo($input_file); $output_file = $path_info['dirname'] . '/' . $path_info['filename'] . '_converted.mp4'; $backup_file = $input_file . '.backup'; // Backup del file originale copy($input_file, $backup_file); $result = convert_video($input_file, $output_file); if ($result['success'] && file_exists($output_file)) { // Sostituisci il file originale con quello convertito unlink($input_file); rename($output_file, $input_file); // Aggiorna il database se l'estensione è cambiata $new_extension = 'mp4'; $old_extension = strtolower($path_info['extension']); if ($old_extension !== $new_extension) { $new_video_url = str_replace('.' . $old_extension, '.' . $new_extension, $lesson['video_url']); $new_file_path = str_replace('.' . $old_extension, '.' . $new_extension, $input_file); rename($input_file, $new_file_path); $stmt = $pdo->prepare("UPDATE lessons SET video_url = ?, video_converted = TRUE WHERE id = ?"); $stmt->execute([$new_video_url, $lesson_id]); } else { // Aggiorna solo il flag video_converted $stmt = $pdo->prepare("UPDATE lessons SET video_converted = TRUE WHERE id = ?"); $stmt->execute([$lesson_id]); } $message = "✅ Video convertito con successo! Il file originale è stato salvato come backup."; // Ricarica la lista $stmt = $pdo->query(" SELECT id, title, video_url, video_platform, video_converted FROM lessons WHERE type = 'video' AND video_platform = 'local' AND video_url IS NOT NULL AND deleted_at IS NULL ORDER BY created_at DESC "); $videos = $stmt->fetchAll(); } else { $error = "❌ Errore durante la conversione: " . htmlspecialchars($result['output']); // Ripristina il backup if (file_exists($backup_file)) { copy($backup_file, $input_file); unlink($backup_file); } } } else { $error = "❌ File video non trovato: " . htmlspecialchars($video_path); } } } } ?>
Questo strumento converte i video in formato MP4 con codec H.264 e AAC per garantire la massima compatibilità con tutti i browser.
Parametri di conversione:
FFmpeg non è installato sul server. Per utilizzare questa funzionalità, installa FFmpeg:
sudo apt-get install ffmpegsudo yum install ffmpegNessun video locale trovato.
| ID | Titolo Lezione | Percorso Video | Formato & Stato | Dimensione | Azione |
|---|---|---|---|---|---|
|
⚠️ File non trovato |
✓ Convertito | MB | ✓ Già convertito Non disponibile |