【发布时间】:2019-05-13 18:02:29
【问题描述】:
我有一个名为 incoming_folder 的目录,其中有一个 mp4 文件。
我想通过php代码实现的是扫描一个incoming_folder目录,找到一个mp4文件,转换成mp3后发送到outgoing_folder。
技术上 outgoing_folder 应该有 mp3 版本的 mp4 来自 incoming_folder
这是我想要的图形表示:
尝试使用以下代码,尽管它扫描了incoming_folder 目录,但没有通过ffmpeg 进行转换。
<?php
$dir = 'in_folder'; /* Place where mp4 file is present */
$files1 = scandir($dir);
print_r($files1); /* It lists all the files in a directory including mp4 file*/
$destination = 'out_folder'; /* Place where mp3 file need to be send after conversion from mp4 */
<?php
foreach($files1 as $f)
{
$parts = pathinfo($f);
switch($parts['extension'])
{
case 'mp4' :
system('ffmpeg -i '.$f.' -map 0:2 -ac 1 '.$destination.DS. $parts['filename'].'.mp3', $result);
if ($result) {
// Do something with result if you want
// log for example
}
break;
case 'mp3' :
// copy($f, $destination. DS . $parts['filename']. '.' . $parts['extension']);
copy($f, $destination.DS.$parts['filename'].'.mp3');
break;
}
}
?>
问题陈述:
我想知道我应该在 php 代码中进行哪些更改,以便文件的转换从 incoming_folder 发生并且应该转到 outgoing_folder。
【问题讨论】: