从文件位置获取视频持续时间,而不使用ffmpeg

时间:2014-06-15 13:10:24

标签: php video ffmpeg duration

function getDuration($file){
        if (file_exists($file)){
         ## open and read video file
        $handle = fopen($file, "r");
        ## read video file size
        $contents = fread($handle, filesize($file));
        fclose($handle);
        $make_hexa = hexdec(bin2hex(substr($contents,strlen($contents)-3)));
        if (strlen($contents) > $make_hexa){
        $pre_duration = hexdec(bin2hex(substr($contents,strlen($contents)-$make_hexa,3))) ;
        $post_duration = $pre_duration/1000;
        $timehours = $post_duration/3600;
        $timeminutes =($post_duration % 3600)/60;
        $timeseconds = ($post_duration % 3600) % 60;
        $timehours = explode(".", $timehours);
        $timeminutes = explode(".", $timeminutes);
        $timeseconds = explode(".", $timeseconds);
        $duration = $timehours[0]. ":" . $timeminutes[0]. ":" . $timeseconds[0];}
        return $duration;
        }
        else {
        return false;
        }
}

此代码工作正常,但对于某些文件,即使文件存在,它也会显示variable $duration is undefined!请帮助别人。

来源 Daniweb

有没有其他方法可以获得视频时长? 它够快吗?

0 个答案:

没有答案