如何使用getID3获取长度视频

时间:2016-04-04 04:02:40

标签: php getid3

我会通过php和getID3库从我的文件视频中获取长度视频,我的视频长度是00:02:03但是这个输出是02:03:00,我怎么能改变

move_uploaded_file($source,$direktori); 
$durasi = getDuration($direktori);
$endtime = date('H:i:s', strtotime($durasi));
echo $endtime;

function getDuration($file){
include_once("getID3/getid3/getid3.php");
$getID3 = new getID3;
$file = $getID3->analyze($file);
return $file['playtime_string'];

}

1 个答案:

答案 0 :(得分:0)

// Using getid3 library, get duration
function get_duration($filename){

    $getID3 = new getID3;

    $file = $getID3->analyze($filename);

    $duration_string = $file['playtime_string'];

    // Format string to be 00:00:00
    return format_duration($duration_string);
}

// Format to AA::BB:CC
function format_duration($duration){

    // The base case is A:BB
    if(strlen($duration) == 4){
        return "00:0" . $duration;
    }
    // If AA:BB
    else if(strlen($duration) == 5){
        return "00:" . $duration;
    }   // If A:BB:CC
    else if(strlen($duration) == 7){
        return "0" . $duration;
    }
}