2012-04-06 19 views
5

Estoy intentando detectar la duración de cualquier archivo de video antes de que se cargue con PHP
así que si es menos de un minuto, por ejemplo, rechazaré subirlo.
si no es posible, ¿cómo puedo hacerlo después de subir el video?¿Cómo puedo detectar la duración del archivo de video en minutos con PHP?

+0

Lo sentimos, no hay ninguno .. primero debe cargar el archivo: D – Baba

+0

@Baba y ¿cómo puedo hacerlo después de cargar el archivo? –

+0

Hm no está realmente seguro acerca de los videos, pero para el audio funciona. Pruebe getID3 http://getid3.sourceforge.net/. Hay algunas clases que se pueden usar para obtener datos de video básicos. – StudioArena

Respuesta

14

Puede obtener video duration con ffmpeg o getID3

Ejemplo

$getID3 = new getID3; 
$file = $getID3->analyze($filename); 
echo("Duration: ".$file['playtime_string']. 
     "/Dimensions: ".$file['video']['resolution_x']." wide by ".$file['video']['resolution_y']." tall". 
     "/Filesize: ".$file['filesize']." bytes<br />"); 

O

ob_start(); 
passthru("ffmpeg -i working_copy.flv 2>&1"); 
$duration = ob_get_contents(); 
$full = ob_get_contents(); 
ob_end_clean(); 
$search = "/duration.*?([0-9]{1,})/"; 
print_r($duration); 
$duration = preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE, 3); 
print_r('<pre>'); 
print_r($matches[1][0]); 
print_r($full); 

favor ver

http://getid3.sourceforge.net/

http://ffmpeg.org/

How to get video duration, dimension and size in PHP?

get flv video length

Gracias

: D

+0

dice que necesita esto antes de subirlo. Gracias: D – kommradHomer

+0

Ver su comentario '@Baba y ¿cómo puedo hacerlo después de subir el archivo? - Ayman Jitan hace 6 minutos''kommradHomer – Baba

+0

wow. Tengo que leer todos los comentarios antes de comentar por no sentir vergüenza – kommradHomer

0

para las personas que vienen a comprobar esto se trata de una solución un poco más avanzado para el año 2017

 first download the latest version from the first link above in the accepted answer the (green checkmark)   

    require_once('getid/getid3/getid3.php'); //path to your get id file if you do not include this in your file it will result in an error meaning the code will not work 
$file = "sade.mp4"; //what you want extract info from maybe mp3,or mp4 file anything you want to get file size in bytes or time duration 
$uuuuu = "videos/"; //path to your video file it could also be music not only video 
$getID3 = new getID3; //initialize engine 
$ThisFileInfo = $getID3->analyze($uuuuu.$file); 
getid3_lib::CopyTagsToComments($ThisFileInfo); 
echo '<pre>'.htmlentities(print_r($ThisFileInfo, true)).'</pre>'; //use this to print array to pick whatever you like that you want value like playduration, filesize 
Cuestiones relacionadas