123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__));
- function CombineMultipleMP3sTo($FilenameOut, $FilenamesIn) {
- foreach ($FilenamesIn as $nextinputfilename) {
- if (is_array($nextinputfilename)) {
- $nextinputfilename = $nextinputfilename[0];
- }
- if (!is_readable($nextinputfilename)) {
- echo 'Cannot read "'.$nextinputfilename.'"<BR>';
- return false;
- }
- }
- if ((file_exists($FilenameOut) && !is_writeable($FilenameOut)) || (!file_exists($FilenameOut) && !is_writeable(dirname($FilenameOut)))) {
- echo 'Cannot write "'.$FilenameOut.'"<BR>';
- return false;
- }
- require_once(dirname(__FILE__).'/../getid3/getid3.php');
- ob_start();
- if ($fp_output = fopen($FilenameOut, 'wb')) {
- ob_end_clean();
-
- $getID3 = new getID3;
- foreach ($FilenamesIn as $nextinputfilename) {
- $startoffset = 0;
- $length_seconds = 0;
- if (is_array($nextinputfilename)) {
- @list($nextinputfilename, $startoffset, $length_seconds) = $nextinputfilename;
- }
- $CurrentFileInfo = $getID3->analyze($nextinputfilename);
- if ($CurrentFileInfo['fileformat'] == 'mp3') {
- ob_start();
- if ($fp_source = fopen($nextinputfilename, 'rb')) {
- ob_end_clean();
- $CurrentOutputPosition = ftell($fp_output);
-
- $start_offset_bytes = $CurrentFileInfo['avdataoffset'];
- if ($startoffset > 0) {
- $start_offset_bytes = $CurrentFileInfo['avdataoffset'] + round(($CurrentFileInfo['bitrate'] / 8) * $startoffset);
- } elseif ($startoffset < 0) {
- $start_offset_bytes = $CurrentFileInfo['avdataend'] + round(($CurrentFileInfo['bitrate'] / 8) * $startoffset);
- }
- $start_offset_bytes = max($CurrentFileInfo['avdataoffset'], min($CurrentFileInfo['avdataend'], $start_offset_bytes));
- $end_offset_bytes = $CurrentFileInfo['avdataend'];
- if ($length_seconds > 0) {
- $end_offset_bytes = $start_offset_bytes + round(($CurrentFileInfo['bitrate'] / 8) * $length_seconds);
- } elseif ($length_seconds < 0) {
- $end_offset_bytes = $CurrentFileInfo['avdataend'] + round(($CurrentFileInfo['bitrate'] / 8) * $length_seconds);
- }
- $end_offset_bytes = max($CurrentFileInfo['avdataoffset'], min($CurrentFileInfo['avdataend'], $end_offset_bytes));
- if ($end_offset_bytes <= $start_offset_bytes) {
- echo 'failed to copy '.$nextinputfilename.' from '.$startoffset.'-seconds start for '.$length_seconds.'-seconds length (not enough data)';
- fclose($fp_source);
- fclose($fp_output);
- return false;
- }
- fseek($fp_source, $start_offset_bytes, SEEK_SET);
- while (!feof($fp_source) && (ftell($fp_source) < $end_offset_bytes)) {
- fwrite($fp_output, fread($fp_source, min(32768, $end_offset_bytes - ftell($fp_source))));
- }
- fclose($fp_source);
- } else {
- $errormessage = ob_get_contents();
- ob_end_clean();
- echo 'failed to open '.$nextinputfilename.' for reading';
- fclose($fp_output);
- return false;
- }
- } else {
- echo $nextinputfilename.' is not MP3 format';
- fclose($fp_output);
- return false;
- }
- }
- } else {
- $errormessage = ob_get_contents();
- ob_end_clean();
- echo 'failed to open '.$FilenameOut.' for writing';
- return false;
- }
- fclose($fp_output);
- return true;
- }
|