繁体   English   中英

如何使用 PHP 以分钟为单位检测视频文件持续时间?

[英]How can I detect video file duration in minutes with PHP?

我试图在使用 PHP 上传之前检测任何视频文件的持续时间
因此,如果少于一分钟,我将拒绝上传。
如果不可能,上传视频后我该怎么做??

您可以使用ffmpeg或 getID3 获取video duration

例子

$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 />");

要么

 ob_start();
 passthru("ffmpeg -i working_copy.flv  2>&1");
 $duration = ob_get_contents();
 $full = ob_get_contents();
 ob_end_clean();
 $search = "/duration.*?([0-9]{1,})/";
 print_r($duration);
 $duration = preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE, 3);
 print_r('<pre>');
 print_r($matches[1][0]);
 print_r($full);

请参见

http://getid3.sourceforge.net/

http://ffmpeg.org/

如何在PHP中获取视频时长、维度和大小?

获取flv视频长度

谢谢

:D

对于前来检查的人来说,这是 2017 年更先进的解决方案

     first download the latest version from the first link above in the accepted answer the (green checkmark)          

     require_once('getid/getid3/getid3.php'); //path to your get id file if you do not include this in your file it will result in an error meaning the code will not work
$file = "sade.mp4"; //what you want extract info from maybe mp3,or mp4 file anything you want to get file size in bytes or time duration
$uuuuu = "videos/"; //path to your video file it could also be music not only video
$getID3 = new getID3; //initialize engine
$ThisFileInfo = $getID3->analyze($uuuuu.$file);
getid3_lib::CopyTagsToComments($ThisFileInfo);
echo '<pre>'.htmlentities(print_r($ThisFileInfo, true)).'</pre>';  //use this to print array to pick whatever you like that you want value like playduration, filesize

暂无
暂无

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

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