繁体   English   中英

获取媒体文件持续时间(服务器端)

[英]Get media file duration (Server-side)

我正在寻找一种方法来获得准确的媒体文件持续时间。 我已经在线研究了许多解决方案,包括getID3库,但ID3标签太容易编辑,或者在某些情况下可能无法填充。 我目前在共享主机上,所以ffmpeg库不是一个选项,因为我无法在此主机上安装任何东西(GoDaddy)。

我目前主要关注MP3,WMV,WAV,MP4,MPEG,AVI和MOV文件。 有没有办法让他们的持续时间使用,最好是PHP? 我会对任何有效的解决方案感到满意。

真的很感激帮助。

谢谢

这个看起来像支持多种媒体格式。

http://www.daniweb.com/web-development/php/threads/428301/getting-video-duration-without-ffmpeg

    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;
            }
        }

要使用它,只需执行以下操作:

## first, define video file and location
$video_file = "somedirectory/video.flv";
## call out the function
echo getDuration($video_file);

我从上面的链接中解决了这个问题。 我在你提到的几种媒体类型上尝试了它,它似乎运行正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM