1. ucob - 27 Ноября, 2011 - 19:25:59 - перейти к сообщению
Можно ли на php обрезать файлы mp3 по определенным секундам, если да, то интересно ка, если нет, то на чем сделать можно.
2. z1o - 04 Декабря, 2011 - 10:34:09 - перейти к сообщению
ucob пишет:
Можно ли на php обрезать файлы mp3 по определенным секундам, если да, то интересно ка, если нет, то на чем сделать можно.
Можно, есть у меня класс для работы с mp3.
Шас поищу и выложу.
(Добавление)
Вот:
PHP:
скопировать код в буфер обмена
скопировать код в буфер обмена
- <?PHP
- class MP3_Crop {
- /**
- * mp3/mpeg file name
- * @var boolean
- */
- var $file = false;
- /**
- * version of bitrate
- * @var integer
- */
- var $bitrate = 0;
- var $layer;
- /**
- * Bytes in file
- * @var integer
- */
- var $filesize = -1;
- /**
- * Byte at which the first mpeg header was found
- * @var integer
- */
- var $frameoffset = -1;
- /**
- * length of mp3 format hh:ss
- * @var string
- */
- /**
- * length of mp3 in seconds
- * @var string
- */
- var $length = false;
- /*
- * creates a new id3 object
- * and loads a tag from a file.
- *
- */
- function MP3_Crop()
- {
- }
- /**
- * reads the given file and parse it
- *
- * @param string $file the name of the file to parse
- * @return mixed PEAR_Error on error
- * @access public
- */
- function read($file)
- {
- $this->file = $file;
- return $this->_readframe();
- }
- /**
- * update the id3v1 tags on the file.
- * Note: If/when ID3v2 is implemented this method will probably get another
- * parameters.
- *
- * @param boolean $v1 if true update/create an id3v1 tag on the file. (defaults to true)
- *
- * @access public
- */
- function write($cropFile, $length = 20)
- {
- $size = ($length * $this->bitrate * 1000) / 8;
- if (!$f)
- {
- return false;
- }
- if (!$f)
- {
- return false;
- }
- return true;
- }
- /**
- * reads a frame from the file
- *
- * @return mixed PEAR_Error when fails
- * @access private
- */
- function _readframe()
- {
- $file = $this->file;
- {
- return false;
- }
- do
- {
- {
- // Find the first frame
- {
- return false;
- }
- }
- // Binary to Hex to a binary sting. ugly but best I can think of.
- } while (!$bits[8] and !$bits[9] and !$bits[10]); // 1st 8 bits true from the while
- $this->frameoffset = $frameoffset;
- if ($bits[11] == 0) {
- );
- } else if ($bits[12] == 0) {
- );
- } else {
- );
- }
- );
- $this->layer = $layer[$bits[13]][$bits[14]];
- $bitrate = 0;
- if ($bits[16] == 1) $bitrate += 8;
- if ($bits[17] == 1) $bitrate += 4;
- if ($bits[18] == 1) $bitrate += 2;
- if ($bits[19] == 1) $bitrate += 1;
- $this->bitrate = $bitrates[$this->layer][$bitrate];
- if ($this->bitrate == 0)
- {
- $this->length = -1;
- return false;
- }
- $this->length = (int)$s;
- return true;
- }
- };
- ?>