是否有任何PHP功能将给我MP3持续时间.我看了ID 3功能,但我没有看到任何持续时间的东西,除此之外,id3是某种标签,它不会在所有MP3中,所以使用这将没有任何意义.
Tec*_*rat 26
安装getid3,但如果只需要持续时间,则可以删除除这些模块之外的所有模块:
使用以下代码访问持续时间:
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($pathName);
$len= @$ThisFileInfo['playtime_string']; // playtime in minutes:seconds, formatted string
Run Code Online (Sandbox Code Playgroud)
在Sourceforge获取它
您可以使用ffmpeg获取mp3或许多其他音频/视频文件的持续时间.
确保你的php不限制php shell_exec.
// Discriminate only the audio/video files you want
if(preg_match('/[^?#]+\.(?:wma|mp3|wav|mp4)/', strtolower($file))){
$filepath = /* your file path */;
// execute ffmpeg form linux shell and grab duration from output
$result = shell_exec("ffmpeg -i ".$filepath.' 2>&1 | grep -o \'Duration: [0-9:.]*\'');
$duration = str_replace('Duration: ', '', $result); // 00:05:03.25
//get the duration in seconds
$timeArr = preg_split('/:/', str_replace('s', '', $duration[0]));
$t = $this->_times[$file] = (($timeArr[3])? $timeArr[3]*1 + $timeArr[2] * 60 + $timeArr[1] * 60 * 60 : $timeArr[2] + $timeArr[1] * 60)*1000;
}
Run Code Online (Sandbox Code Playgroud)小智 8
我已经度过了这么多时间,但是没有getID3(http://getid3.sourceforge.net/)来获取音频文件的持续时间是不可能的.
1)首先使用以下链接下载getID3库:
https://github.com/JamesHeinrich/getID3/archive/master.zip
Run Code Online (Sandbox Code Playgroud)
2)尝试以下代码:
<?php
include("getid3/getid3.php");
$filename = 'bcd4ecc6bf521da9b9a2d8b9616d1505.wav';
$getID3 = new getID3;
$file = $getID3->analyze($filename);
$playtime_seconds = $file['playtime_seconds'];
echo gmdate("H:i:s", $playtime_seconds);
?>
Run Code Online (Sandbox Code Playgroud)