开发者

is there a good library out there that will split a mp3 with php [closed]

开发者 https://www.devze.com 2023-03-04 20:04 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We d开发者_JAVA百科on’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 2 years ago.

Improve this question

So i have an application takes a uploaded song and allows the user to purchase it. I would like to also create a 30 second clip that the user can preview, but rather then having the user upload two files I want the application to create the 30 second mp3 file based on the original mp3. I found this library which i am using like this

    $oSplit=new CMP3Split(DIR_DOWNLOAD ."Made_To_Love.mp3",243,DIR_DOWNLOAD ."clips/{$rndString}.mp3",30,0);

but it seems to not always produce a 30 second clip

and i also found this question which is using ffmpeg which i dont know how to use in a php setting.

Any ideas or suggestions


That library is largely useless: it doesn't actually even read the MP3's bitrate to figure out how much of the file to output.

Take a look at this: http://www.sourcerally.net/Scripts/20-PHP-MP3-Class

That class should be able to extract with something like this:

  header('Content-type: audio/mp3');
  header('Content-disposition: attachment; filename="preview.mp3"');
  header('Cache-Control: no-cache');
  include_once('mp3.php');
  $path = '<filename to path>';
  $mp3 = new mp3($path);
  $mp3_1 = $mp3->extract(0,30);
  header('Content-length: ' . sizeof($mp3_1->str));
  echo $mp3_1->str;

You can expect it to be slow, and consume a lot of memory: you're probably better off using something like ffmpeg to do the chop.


Try out the ffmpeg solution from the command line, if you get it working just call it at the command line from within PHP. shell_exec() can do this. If you're allowing the user to specify a file name you will want to escape the shell arguments.

Since this will take a moment, it may be wise to look into passing this work off to a queue system like gearman.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号