How to find the bytes per second
I want to find how many bytes per second are used in a mp3 file in order to be able to find the duration of the audio file. Im using the script below and it shows me some strange values. Im not really familiar with all this audio file things and i would appreciate some help.
function getDuration($file) {
$fp = fopen($file, 'rb');
$size_in_bytes = filesiz开发者_运维知识库e($file);
fseek($fp, 20);
$rawheader = fread($fp, 16);
$header = unpack('vtype/vchannels/Vsamplerate/Vbytespersec/valignment/vbits', $rawheader);
print_r($header);
$sec = ceil($size_in_bytes/$header['bytespersec']);
return $sec;
}
The output on print_r is
Array ( [type] => 25936 [channels] => 27489 [samplerate] => 1970037078 [bytespersec] => 2110652517 [alignment] => 0 [bits] => 21072 )
So this bytespersec rate (2 110 652 517) is confusing me.
maybe you can use the ffmpeg extension for php?
http://ffmpeg-php.sourceforge.net/doc/api/ffmpeg_movie.php
精彩评论