getId3 to get video duration in seconds

3.4k Views Asked by At

How do i get getId3's playtime_string duration in seconds? Is there away to get directly in seconds? Without using other php functions to look at the string and pull it out of the value?

  <?php require_once('getid3/getid3.php');
    $filename='uploads/4thofJuly_184.mp4';
    $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 />");
    $getID3 = new getID3;
    $filename='uploads/25PercentOff_710.wmv';
    $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 />");

    // Calling getimagesize() function 
    $filename="uploads/25PercentOff_960.jpg";
    list($width, $height) = getimagesize($filename); 

    // Displaying dimensions of the image 
    echo "Width of image : " . $width . "<br>"; 

    echo "Height of image : " . $height . "<br>"; 
2

There are 2 best solutions below

0
codernoob8 On BEST ANSWER

in this situation use $file['playtime_seconds'] it will give you the seconds directly with a decimal point. Which you can format using php's round() or floor() functions depending on how you want it to display.

0
Abbas On

There is a very simple answer to that: Instead of using $file['playtime_string'] just use: $file['playtime_seconds']