getId3 以秒为单位获取视频时长

getId3 to get video duration in seconds

如何获取 getId3 的 playtime_string 持续时间(以秒为单位)?有没有直接秒掉的?不使用其他 php 函数查看字符串并将其从值中提取出来?

  <?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>"; 

在这种情况下使用 $file['playtime_seconds'] 它会直接给你带小数点的秒数。您可以使用 php 的 round()floor() 函数对其进行格式化,具体取决于您希望它如何显示。

对此有一个非常简单的答案: 而不是使用 $file['playtime_string'] 只需使用:$file['playtime_seconds']