FFMPEG使用PHP变量将WAV转换为MP3


ffmpeg convert wav to mp3 using php variable

我正在开发一个php函数来上传.wav并在同一文件夹中创建它的.mp3版本。到目前为止,除了我尝试使用时,一切都在正常工作:

 shell_exec('ffmpeg -i ' . $file_path . '-f mp2 ' . $mp3name); 

在函数中,它不会在 Beats 文件夹中创建.mp3。

我试过了

shell_exec('ffmpeg -i test.wav -f mp2 test.mp3'); 

它本身,效果很好。

php 函数:

function upload_a_sound($user_id, $file_temp, $file_extn, $name, $uploader, $keywords) {
    $timecode = substr(md5(time()), 0, 10);
    $mp3name = 'beats/' . $timecode . '.mp3';
    $file_path = 'beats/' . $timecode . '.' . $file_extn;
    //$date = date('m-d-Y');
    move_uploaded_file($file_temp, $file_path);
    shell_exec('ffmpeg -i ' . $file_path . '-f mp2 ' . $mp3name); 
    require ('classAudioFile.php');
    $AF = new AudioFile;
    $AF->loadFile($file_path);
    $AF->visual_width=200;
    $AF->visual_height=200;
    $AF->visual_graph_color="#c491db";
    $AF->visual_background_color="#000000";
    $AF->visual_grid=false;
    $AF->visual_border=false;
    $AF->visual_graph_mode=0;
    $AF->getVisualization ('images/song/' . $timecode . '.png');
    $imageloc = 'images/song/' . $timecode . '.png';
    mysql_query("INSERT INTO `content` VALUES ('', '', '$name', '$uploader', '$keywords', '$file_path', '$imageloc', '$mp3name')");
}

这是代码的工作版本,我相信这是语法上的东西,我必须在 $mp 3name shell 执行后放置一个 '

function upload_a_sound($user_id, $file_temp, $file_extn, $name, $uploader, $keywords) {
    $timecode = substr(md5(time()), 0, 10);
    $mp3name = 'beats/' . $timecode . '.mp3';
    $wavname = 'beats/' . $timecode . '.wav';
    $file_path = 'beats/' . $timecode . '.' . $file_extn;
    //$date = date('m-d-Y');
    move_uploaded_file($file_temp, $file_path);
    shell_exec('ffmpeg -i ' . $wavname . ' -vn -ar 44100 -ac 2 -ab 192k -f mp3 ' . $mp3name . ''); 
    require ('classAudioFile.php');
    $AF = new AudioFile;
    $AF->loadFile($file_path);
    $AF->visual_width=200;
    $AF->visual_height=200;
    $AF->visual_graph_color="#c491db";
    $AF->visual_background_color="#000000";
    $AF->visual_grid=false;
    $AF->visual_border=false;
    $AF->visual_graph_mode=0;
    $AF->getVisualization ('images/song/' . $timecode . '.png');
    $imageloc = 'images/song/' . $timecode . '.png';
    mysql_query("INSERT INTO `content` VALUES ('', '', '$name', '$uploader', '$keywords', '$file_path', '$imageloc', '$mp3name')");