Convert .mp4 to .mp3 using pure PHP [closed]

2019-02-11 06:35发布

How do I convert a video (.mp4) from an external site (ex: youtube.com) to an .mp3 using PHP without wasting a lot of resources? So similar to http://youtube-mp3.org/, they are able to convert it very easily.

Thanks.

标签: php mp3 mp4
2条回答
可以哭但决不认输i
2楼-- · 2019-02-11 06:42

Pure PHP is not suitable for this task.

Let the user upload the file via PHP. Then direct PHP (via the exec() function) an external program like ffmpeg or gstreamer to convert the file. After the conversion you can make the mp3 available for downloading via PHP.

This is in my opinion the only suitable approach to this kind of problem, because programs like ffmpeg use much less resources than a PHP Script would need.

查看更多
我命由我不由天
3楼-- · 2019-02-11 07:02

you can convert it by shell-command eg [*]

  <?php 
      exec('ffmpeg -i video.mp4 -f mp3 -ab 192000 -vn music.mp3');
  ?>
  • if your OS is unix and ffmpeg is installed
查看更多
登录 后发表回答