dongsu1539 2017-07-10 06:02
浏览 194

在PHP中获取视频的确切持续时间

I'm trying to get the exact time duration of a video in PHP. I have searched about it, but it seems to be like, I have to use the library called getid3, but I don't want to use it. Then I searched some code, until I found this code, but, it is wrong because, if I have 00:03:43 (hr:min:sec), the result is different. Here's my code:

    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) + 1;
            $timehours = explode(".", $timehours);
            $timeminutes = explode(".", $timeminutes);
            $timeseconds = explode(".", $timeseconds);
            $duration = $timehours[0]. ":" . $timeminutes[0] . ":" . $timeseconds[0];
        }
        return $duration;
    }
    else {
        return 'File doesn\'t exists.';
    }

Note: I'm using Laravel5.1

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于单片机的靶位控制系统
    • ¥15 AT89C51控制8位八段数码管显示时钟。
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错