fix
This commit is contained in:
@@ -669,4 +669,67 @@ function redirect($url) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Estrae la durata di un video in minuti
|
||||
*
|
||||
* @param string $file_path Percorso del file video
|
||||
* @return int|null Durata in minuti o null se non rilevabile
|
||||
*/
|
||||
function get_video_duration($file_path) {
|
||||
// Metodo 1: Usa getID3 se disponibile
|
||||
if (file_exists(__DIR__ . '/../vendor/getid3/getid3/getid3.php')) {
|
||||
require_once __DIR__ . '/../vendor/getid3/getid3/getid3.php';
|
||||
|
||||
try {
|
||||
$getID3 = new getID3();
|
||||
$file_info = $getID3->analyze($file_path);
|
||||
|
||||
if (isset($file_info['playtime_seconds'])) {
|
||||
return (int) ceil($file_info['playtime_seconds'] / 60);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// Continua con altri metodi
|
||||
}
|
||||
}
|
||||
|
||||
// Metodo 2: Usa ffprobe se disponibile
|
||||
if (function_exists('shell_exec') && !in_array('shell_exec', explode(',', ini_get('disable_functions')))) {
|
||||
$ffprobe_commands = [
|
||||
'ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 ' . escapeshellarg($file_path),
|
||||
'/usr/bin/ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 ' . escapeshellarg($file_path),
|
||||
'/usr/local/bin/ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 ' . escapeshellarg($file_path)
|
||||
];
|
||||
|
||||
foreach ($ffprobe_commands as $cmd) {
|
||||
$output = @shell_exec($cmd . ' 2>&1');
|
||||
if ($output && is_numeric(trim($output))) {
|
||||
$seconds = (float) trim($output);
|
||||
return (int) ceil($seconds / 60);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Metodo 3: Usa ffmpeg se disponibile
|
||||
if (function_exists('shell_exec') && !in_array('shell_exec', explode(',', ini_get('disable_functions')))) {
|
||||
$ffmpeg_commands = [
|
||||
'ffmpeg -i ' . escapeshellarg($file_path) . ' 2>&1',
|
||||
'/usr/bin/ffmpeg -i ' . escapeshellarg($file_path) . ' 2>&1',
|
||||
'/usr/local/bin/ffmpeg -i ' . escapeshellarg($file_path) . ' 2>&1'
|
||||
];
|
||||
|
||||
foreach ($ffmpeg_commands as $cmd) {
|
||||
$output = @shell_exec($cmd);
|
||||
if ($output && preg_match('/Duration: (\d{2}):(\d{2}):(\d{2})/', $output, $matches)) {
|
||||
$hours = (int) $matches[1];
|
||||
$minutes = (int) $matches[2];
|
||||
$seconds = (int) $matches[3];
|
||||
return $hours * 60 + $minutes + (int) ceil($seconds / 60);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Nessun metodo funzionante
|
||||
return null;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user