PHP function lấy thời gian độ dài file wav

  1. function wavDur($file) {
  2. $fp = fopen($file, 'r');
  3. if (fread($fp,4) == 'RIFF') {
  4. fseek($fp, 20);
  5. $rawheader = fread($fp, 16);
  6. $header = unpack('vtype/vchannels/Vsamplerate/Vbytespersec/valignment/vbits',$rawheader);
  7. $pos = ftell($fp);
  8. while (fread($fp,4) != 'data' && !feof($fp)) {
  9. $pos++;
  10. fseek($fp,$pos);
  11. }
  12. $rawheader = fread($fp, 4);
  13. $data = unpack('Vdatasize',$rawheader);
  14. $sec = $data['datasize']/$header['bytespersec'];
  15. $minutes = intval(($sec / 60) % 60);
  16. $seconds = intval($sec % 60);
  17. return round($sec);
  18. return str_pad($minutes,2,'0', STR_PAD_LEFT).':'.str_pad($seconds,2,'0', STR_PAD_LEFT);
  19. }
  20. }

Leave a Reply

You must be logged in to post a comment.